Skip to content

Commit 728db88

Browse files
benleshalxhub
authored andcommitted
fix(core): CSS sanitizer now allows parens in file names (#30322)
Resolves an issue where images that were created with a name like `'foo (1).png'` would not pass CSS url sanitization. PR Close #30322
1 parent 9a807bd commit 728db88

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

‎packages/core/src/sanitization/style_sanitizer.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const SAFE_STYLE_VALUE = new RegExp(
5454
* Given the common use case, low likelihood of attack vector, and low impact of an attack, this
5555
* code is permissive and allows URLs that sanitize otherwise.
5656
*/
57-
const URL_RE = /^url\(([^)]+)\)$/;
57+
const URL_RE = /^url\(([\w\W]*)\)$/;
5858

5959
/**
6060
* Checks that quotes (" and ') are properly balanced inside a string. Assumes

‎packages/core/test/sanitization/style_sanitizer_spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {_sanitizeStyle} from '../../src/sanitization/style_sanitizer';
3232
expectSanitize('rgb(255, 0, 0)').toEqual('rgb(255, 0, 0)');
3333
expectSanitize('expression(haha)').toEqual('unsafe');
3434
});
35-
t.it('rejects unblanaced quotes', () => { expectSanitize('"value" "').toEqual('unsafe'); });
35+
t.it('rejects unbalanced quotes', () => { expectSanitize('"value" "').toEqual('unsafe'); });
3636
t.it('accepts transform functions', () => {
3737
expectSanitize('rotate(90deg)').toEqual('rotate(90deg)');
3838
expectSanitize('rotate(javascript:evil())').toEqual('unsafe');
@@ -58,6 +58,7 @@ import {_sanitizeStyle} from '../../src/sanitization/style_sanitizer';
5858
t.it('accepts quoted URLs', () => {
5959
expectSanitize('url("foo/bar.png")').toEqual('url("foo/bar.png")');
6060
expectSanitize(`url('foo/bar.png')`).toEqual(`url('foo/bar.png')`);
61+
expectSanitize(`url('foo/bar (1).png')`).toEqual(`url('foo/bar (1).png')`);
6162
expectSanitize(`url( 'foo/bar.png'\n )`).toEqual(`url( 'foo/bar.png'\n )`);
6263
expectSanitize('url("javascript:evil()")').toEqual('unsafe');
6364
expectSanitize('url( " javascript:evil() " )').toEqual('unsafe');

0 commit comments

Comments
 (0)