Skip to content

Commit a03cb11

Browse files
committed
JS: Include $().prop() source in XssThroughDom
1 parent 2f3a76c commit a03cb11

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ module XssThroughDom {
4040
(
4141
this.getMethodName() = ["text", "val"] and this.getNumArgument() = 0
4242
or
43-
this.getMethodName() = "attr" and
44-
this.getNumArgument() = 1 and
45-
forex(InferredType t | t = this.getArgument(0).analyze().getAType() | t = TTString()) and
46-
this.getArgument(0).mayHaveStringValue(unsafeAttributeName())
43+
exists(string methodName, string value |
44+
this.getMethodName() = methodName and
45+
this.getNumArgument() = 1 and
46+
forex(InferredType t | t = this.getArgument(0).analyze().getAType() | t = TTString()) and
47+
this.getArgument(0).mayHaveStringValue(value)
48+
|
49+
methodName = "attr" and value = unsafeAttributeName()
50+
or
51+
methodName = "prop" and value = unsafeDomPropertyName()
52+
)
4753
) and
4854
// looks like a $("<p>" + ... ) source, which is benign for this query.
4955
not exists(DataFlow::Node prefix |

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ nodes
100100
| xss-through-dom.js:79:4:79:34 | documen ... t.value |
101101
| xss-through-dom.js:79:4:79:34 | documen ... t.value |
102102
| xss-through-dom.js:79:4:79:34 | documen ... t.value |
103+
| xss-through-dom.js:81:17:81:43 | $('#foo ... rText') |
104+
| xss-through-dom.js:81:17:81:43 | $('#foo ... rText') |
105+
| xss-through-dom.js:81:17:81:43 | $('#foo ... rText') |
103106
edges
104107
| forms.js:8:23:8:28 | values | forms.js:9:31:9:36 | values |
105108
| forms.js:8:23:8:28 | values | forms.js:9:31:9:36 | values |
@@ -157,6 +160,7 @@ edges
157160
| xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name | xss-through-dom.js:73:9:73:41 | selector |
158161
| xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name | xss-through-dom.js:73:9:73:41 | selector |
159162
| xss-through-dom.js:79:4:79:34 | documen ... t.value | xss-through-dom.js:79:4:79:34 | documen ... t.value |
163+
| xss-through-dom.js:81:17:81:43 | $('#foo ... rText') | xss-through-dom.js:81:17:81:43 | $('#foo ... rText') |
160164
#select
161165
| forms.js:9:31:9:40 | values.foo | forms.js:8:23:8:28 | values | forms.js:9:31:9:40 | values.foo | $@ is reinterpreted as HTML without escaping meta-characters. | forms.js:8:23:8:28 | values | DOM text |
162166
| forms.js:12:31:12:40 | values.bar | forms.js:11:24:11:29 | values | forms.js:12:31:12:40 | values.bar | $@ is reinterpreted as HTML without escaping meta-characters. | forms.js:11:24:11:29 | values | DOM text |
@@ -185,3 +189,4 @@ edges
185189
| xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name | xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name | xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name | $@ is reinterpreted as HTML without escaping meta-characters. | xss-through-dom.js:71:11:71:32 | $("inpu ... 0).name | DOM text |
186190
| xss-through-dom.js:77:4:77:11 | selector | xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name | xss-through-dom.js:77:4:77:11 | selector | $@ is reinterpreted as HTML without escaping meta-characters. | xss-through-dom.js:73:20:73:41 | $("inpu ... 0).name | DOM text |
187191
| xss-through-dom.js:79:4:79:34 | documen ... t.value | xss-through-dom.js:79:4:79:34 | documen ... t.value | xss-through-dom.js:79:4:79:34 | documen ... t.value | $@ is reinterpreted as HTML without escaping meta-characters. | xss-through-dom.js:79:4:79:34 | documen ... t.value | DOM text |
192+
| xss-through-dom.js:81:17:81:43 | $('#foo ... rText') | xss-through-dom.js:81:17:81:43 | $('#foo ... rText') | xss-through-dom.js:81:17:81:43 | $('#foo ... rText') | $@ is reinterpreted as HTML without escaping meta-characters. | xss-through-dom.js:81:17:81:43 | $('#foo ... rText') | DOM text |

javascript/ql/test/query-tests/Security/CWE-079/XssThroughDom/xss-through-dom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,6 @@
7777
$(selector); // NOT OK
7878

7979
$(document.my_form.my_input.value); // NOT OK
80+
81+
$("#id").html( $('#foo').prop('innerText') ); // NOT OK
8082
})();

0 commit comments

Comments
 (0)