Skip to content

Commit ccdc821

Browse files
committed
add xlink:href as xss target when using setAttribute
1 parent d2336dc commit ccdc821

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/DOM.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class DomMethodCallExpr extends MethodCallExpr {
8585
name = "setAttributeNS" and argPos = 2
8686
) and
8787
// restrict to potentially dangerous attributes
88-
exists(string attr | attr = "action" or attr = "formaction" or attr = "href" or attr = "src" |
88+
exists(string attr |
89+
attr = "action" or attr = "formaction" or attr = "href" or attr = "src" or attr = "xlink:href" |
8990
getArgument(argPos - 1).getStringValue().toLowerCase() = attr
9091
)
9192
)

javascript/ql/test/query-tests/Security/CWE-079/Xss.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ nodes
5858
| tst3.js:4:25:4:32 | data.src |
5959
| tst3.js:5:26:5:29 | data |
6060
| tst3.js:5:26:5:31 | data.p |
61+
| tst3.js:7:32:7:35 | data |
62+
| tst3.js:7:32:7:37 | data.p |
6163
| tst.js:2:7:2:39 | target |
6264
| tst.js:2:16:2:32 | document.location |
6365
| tst.js:2:16:2:39 | documen ... .search |
@@ -226,12 +228,14 @@ edges
226228
| translate.js:7:42:7:60 | target.substring(1) | translate.js:9:27:9:50 | searchP ... 'term') |
227229
| tst3.js:2:12:2:75 | JSON.pa ... tr(1))) | tst3.js:4:25:4:28 | data |
228230
| tst3.js:2:12:2:75 | JSON.pa ... tr(1))) | tst3.js:5:26:5:29 | data |
231+
| tst3.js:2:12:2:75 | JSON.pa ... tr(1))) | tst3.js:7:32:7:35 | data |
229232
| tst3.js:2:23:2:74 | decodeU ... str(1)) | tst3.js:2:12:2:75 | JSON.pa ... tr(1))) |
230233
| tst3.js:2:42:2:56 | window.location | tst3.js:2:42:2:63 | window. ... .search |
231234
| tst3.js:2:42:2:63 | window. ... .search | tst3.js:2:42:2:73 | window. ... bstr(1) |
232235
| tst3.js:2:42:2:73 | window. ... bstr(1) | tst3.js:2:23:2:74 | decodeU ... str(1)) |
233236
| tst3.js:4:25:4:28 | data | tst3.js:4:25:4:32 | data.src |
234237
| tst3.js:5:26:5:29 | data | tst3.js:5:26:5:31 | data.p |
238+
| tst3.js:7:32:7:35 | data | tst3.js:7:32:7:37 | data.p |
235239
| tst.js:2:7:2:39 | target | tst.js:5:18:5:23 | target |
236240
| tst.js:2:7:2:39 | target | tst.js:12:28:12:33 | target |
237241
| tst.js:2:7:2:39 | target | tst.js:23:42:23:47 | target |
@@ -361,6 +365,7 @@ edges
361365
| translate.js:9:27:9:50 | searchP ... 'term') | translate.js:6:16:6:32 | document.location | translate.js:9:27:9:50 | searchP ... 'term') | Cross-site scripting vulnerability due to $@. | translate.js:6:16:6:32 | document.location | user-provided value |
362366
| tst3.js:4:25:4:32 | data.src | tst3.js:2:42:2:56 | window.location | tst3.js:4:25:4:32 | data.src | Cross-site scripting vulnerability due to $@. | tst3.js:2:42:2:56 | window.location | user-provided value |
363367
| tst3.js:5:26:5:31 | data.p | tst3.js:2:42:2:56 | window.location | tst3.js:5:26:5:31 | data.p | Cross-site scripting vulnerability due to $@. | tst3.js:2:42:2:56 | window.location | user-provided value |
368+
| tst3.js:7:32:7:37 | data.p | tst3.js:2:42:2:56 | window.location | tst3.js:7:32:7:37 | data.p | Cross-site scripting vulnerability due to $@. | tst3.js:2:42:2:56 | window.location | user-provided value |
364369
| tst.js:5:18:5:23 | target | tst.js:2:16:2:32 | document.location | tst.js:5:18:5:23 | target | Cross-site scripting vulnerability due to $@. | tst.js:2:16:2:32 | document.location | user-provided value |
365370
| tst.js:8:18:8:126 | "<OPTIO ... PTION>" | tst.js:8:37:8:53 | document.location | tst.js:8:18:8:126 | "<OPTIO ... PTION>" | Cross-site scripting vulnerability due to $@. | tst.js:8:37:8:53 | document.location | user-provided value |
366371
| tst.js:12:5:12:42 | '<div s ... 'px">' | tst.js:2:16:2:32 | document.location | tst.js:12:5:12:42 | '<div s ... 'px">' | Cross-site scripting vulnerability due to $@. | tst.js:2:16:2:32 | document.location | user-provided value |

javascript/ql/test/query-tests/Security/CWE-079/tst3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var data = JSON.parse(decodeURIComponent(window.location.search.substr(1)));
44
foo.setAttribute("src", data.src); // NOT OK
55
foo.setAttribute("HREF", data.p); // NOT OK
66
foo.setAttribute("width", data.w); // OK
7+
foo.setAttribute("xlink:href", data.p) // NOT OK
78

89
for (var p in data)
910
foo.setAttribute(p, data[p]); // not flagged since attribute name is unknown

0 commit comments

Comments
 (0)