Skip to content

Commit 35c847b

Browse files
committed
Add more xss tests
1 parent 54dfda3 commit 35c847b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

dash/dash-renderer/src/utils/clientsideFunctions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const clean_url = (url: string, fallback = 'about:blank') => {
3434
const cleaned = url
3535
.replace(newLines, '')
3636
.replace(ctrlChars, '')
37-
.replace(htmlEntities, '');
37+
.replace(htmlEntities, (_, dec) => String.fromCharCode(dec))
38+
.trim();
3839
if (invalidProtocols.test(cleaned)) {
3940
return fallback;
4041
}

tests/integration/security/test_xss.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@ def test_xss001_banned_protocols(dash_duo):
99
dcc.Link("dcc-link", href="javascript:alert(1)", id="dcc-link"),
1010
html.Br(),
1111
html.A(
12-
"html.A", href='javascr\nipt:alert(1);console.log("xss");', id="html-A"
12+
"html.A",
13+
href='javascr\n\nipt:alert(1);console.log("xss");',
14+
id="html-A",
15+
),
16+
html.A(
17+
"html.A.escape",
18+
id="html-A-escape",
19+
href="""javascript\x09\x0a:alert(1)""",
20+
),
21+
html.A(
22+
"html.A.encoded",
23+
id="html-A-encoded",
24+
href="&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041",
1325
),
1426
html.Br(),
1527
html.Form(
@@ -35,6 +47,8 @@ def test_xss001_banned_protocols(dash_duo):
3547
for element_id, prop in (
3648
("#dcc-link", "href"),
3749
("#html-A", "href"),
50+
("#html-A-escape", "href"),
51+
("#html-A-encoded", "href"),
3852
("#iframe-src", "src"),
3953
("#object-data", "data"),
4054
("#embed-src", "src"),

0 commit comments

Comments
 (0)