Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
feat(): whitelist blob urls for sanitization of data-bound image urls
Browse files Browse the repository at this point in the history
Closes #4623
  • Loading branch information
IgorMinar committed Mar 10, 2014
1 parent b700282 commit 47ab8df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/ng/sanitizeUri.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
function $$SanitizeUriProvider() {
var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/,
imgSrcSanitizationWhitelist = /^\s*(https?|ftp|file):|data:image\//;
imgSrcSanitizationWhitelist = /^\s*(https?|ftp|file|blob):|data:image\//;

/**
* @description
Expand Down
20 changes: 12 additions & 8 deletions test/ng/sanitizeUriSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ describe('sanitizeUri', function() {
expect(sanitizeImg(testUrl)).toBe("unsafe:data:,foo");
});

it('should not sanitize data: URIs for images', function() {
// image data uri
// ref: http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
testUrl = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
expect(sanitizeImg(testUrl)).toBe('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
});

it('should sanitize mailto: urls', function() {
testUrl = "mailto:foo@bar.com";
expect(sanitizeImg(testUrl)).toBe('unsafe:mailto:foo@bar.com');
Expand Down Expand Up @@ -113,6 +106,17 @@ describe('sanitizeUri', function() {
expect(sanitizeImg(testUrl)).toBe('file:///foo/bar.html');
});

it('should not sanitize blob urls', function() {
testUrl = "blob:///foo/bar.html";
expect(sanitizeImg(testUrl)).toBe('blob:///foo/bar.html');
});

it('should not sanitize data: URIs for images', function() {
// image data uri
// ref: http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
testUrl = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
expect(sanitizeImg(testUrl)).toBe('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
});

it('should allow reconfiguration of the src whitelist', function() {
var returnVal;
Expand Down Expand Up @@ -227,4 +231,4 @@ describe('sanitizeUri', function() {

});

});
});

0 comments on commit 47ab8df

Please sign in to comment.