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

Commit 47ab8df

Browse files
committed
feat(): whitelist blob urls for sanitization of data-bound image urls
Closes #4623
1 parent b700282 commit 47ab8df

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/ng/sanitizeUri.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
function $$SanitizeUriProvider() {
88
var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/,
9-
imgSrcSanitizationWhitelist = /^\s*(https?|ftp|file):|data:image\//;
9+
imgSrcSanitizationWhitelist = /^\s*(https?|ftp|file|blob):|data:image\//;
1010

1111
/**
1212
* @description

test/ng/sanitizeUriSpec.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ describe('sanitizeUri', function() {
3737
expect(sanitizeImg(testUrl)).toBe("unsafe:data:,foo");
3838
});
3939

40-
it('should not sanitize data: URIs for images', function() {
41-
// image data uri
42-
// ref: http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
43-
testUrl = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
44-
expect(sanitizeImg(testUrl)).toBe('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
45-
});
46-
4740
it('should sanitize mailto: urls', function() {
4841
testUrl = "mailto:[email protected]";
4942
expect(sanitizeImg(testUrl)).toBe('unsafe:mailto:[email protected]');
@@ -113,6 +106,17 @@ describe('sanitizeUri', function() {
113106
expect(sanitizeImg(testUrl)).toBe('file:///foo/bar.html');
114107
});
115108

109+
it('should not sanitize blob urls', function() {
110+
testUrl = "blob:///foo/bar.html";
111+
expect(sanitizeImg(testUrl)).toBe('blob:///foo/bar.html');
112+
});
113+
114+
it('should not sanitize data: URIs for images', function() {
115+
// image data uri
116+
// ref: http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
117+
testUrl = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
118+
expect(sanitizeImg(testUrl)).toBe('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
119+
});
116120

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

228232
});
229233

230-
});
234+
});

0 commit comments

Comments
 (0)