Skip to content

Commit a360309

Browse files
jelbournalxhub
authored andcommitted
refactor(core): remove obsolete data: url validation (angular#45860)
Validation for `data:` urls is obsolete now that modern browsers ([Firefox as of v57+](https://blog.mozilla.org/security/2017/10/04/treating-data-urls-unique-origins-firefox-57)) don't treat `data:` urls as same-origin resources. Googlers can see internal change cl/363609175 for additional context. PR Close angular#45860
1 parent ce76103 commit a360309

File tree

3 files changed

+2
-17
lines changed

3 files changed

+2
-17
lines changed

packages/core/src/sanitization/url_sanitizer.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,11 @@
3333
*
3434
* This regular expression was taken from the Closure sanitization library.
3535
*/
36-
const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^&:/?#]*(?:[/?#]|$))/gi;
37-
38-
/* A pattern that matches safe srcset values */
39-
const SAFE_SRCSET_PATTERN = /^(?:(?:https?|file):|[^&:/?#]*(?:[/?#]|$))/gi;
40-
41-
/** A pattern that matches safe data URLs. Only matches image, video and audio types. */
42-
const DATA_URL_PATTERN =
43-
/^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[a-z0-9+\/]+=*$/i;
36+
const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|data|ftp|tel|file|sms):|[^&:/?#]*(?:[/?#]|$))/gi;
4437

4538
export function _sanitizeUrl(url: string): string {
4639
url = String(url);
47-
if (url.match(SAFE_URL_PATTERN) || url.match(DATA_URL_PATTERN)) return url;
40+
if (url.match(SAFE_URL_PATTERN)) return url;
4841

4942
if (typeof ngDevMode === 'undefined' || ngDevMode) {
5043
console.warn(`WARNING: sanitizing unsafe URL value ${url} (see https://g.co/ng/security#xss)`);

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@
110110
{
111111
"name": "Console"
112112
},
113-
{
114-
"name": "DATA_URL_PATTERN"
115-
},
116113
{
117114
"name": "DEFAULT_SERIALIZER"
118115
},

packages/core/test/sanitization/url_sanitizer_spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
6666
'&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74:',
6767
'jav	ascript:alert();',
6868
'jav\u0000ascript:alert();',
69-
'data:;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
70-
'data:,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
71-
'data:iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
72-
'data:text/javascript;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
73-
'data:application/x-msdownload;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
7469
];
7570
for (const url of invalidUrls) {
7671
it(`valid ${url}`, () => expect(_sanitizeUrl(url)).toMatch(/^unsafe:/));

0 commit comments

Comments
 (0)