Skip to content

Commit 0435cee

Browse files
committed
add a taint-step through URL.createObjectURL for js/xss-through-dom
1 parent b11d48e commit 0435cee

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/XssThroughDomQuery.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class Configuration extends TaintTracking::Configuration {
3636
DomBasedXss::isOptionallySanitizedEdge(pred, succ)
3737
}
3838

39+
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
40+
succ = DataFlow::globalVarRef("URL").getAMemberCall("createObjectURL") and
41+
pred = succ.(DataFlow::InvokeNode).getArgument(0)
42+
}
43+
3944
override predicate hasFlowPath(DataFlow::SourcePathNode src, DataFlow::SinkPathNode sink) {
4045
super.hasFlowPath(src, sink) and
4146
// filtering away readings of `src` that end in a URL sink.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ nodes
134134
| xss-through-dom.js:120:23:120:40 | ev.target.files[0] |
135135
| xss-through-dom.js:120:23:120:45 | ev.targ ... 0].name |
136136
| xss-through-dom.js:120:23:120:45 | ev.targ ... 0].name |
137+
| xss-through-dom.js:122:33:122:71 | URL.cre ... les[0]) |
138+
| xss-through-dom.js:122:33:122:71 | URL.cre ... les[0]) |
139+
| xss-through-dom.js:122:53:122:67 | ev.target.files |
140+
| xss-through-dom.js:122:53:122:67 | ev.target.files |
141+
| xss-through-dom.js:122:53:122:70 | ev.target.files[0] |
137142
edges
138143
| forms.js:8:23:8:28 | values | forms.js:9:31:9:36 | values |
139144
| forms.js:8:23:8:28 | values | forms.js:9:31:9:36 | values |
@@ -216,6 +221,10 @@ edges
216221
| xss-through-dom.js:120:23:120:37 | ev.target.files | xss-through-dom.js:120:23:120:40 | ev.target.files[0] |
217222
| xss-through-dom.js:120:23:120:40 | ev.target.files[0] | xss-through-dom.js:120:23:120:45 | ev.targ ... 0].name |
218223
| xss-through-dom.js:120:23:120:40 | ev.target.files[0] | xss-through-dom.js:120:23:120:45 | ev.targ ... 0].name |
224+
| xss-through-dom.js:122:53:122:67 | ev.target.files | xss-through-dom.js:122:53:122:70 | ev.target.files[0] |
225+
| xss-through-dom.js:122:53:122:67 | ev.target.files | xss-through-dom.js:122:53:122:70 | ev.target.files[0] |
226+
| xss-through-dom.js:122:53:122:70 | ev.target.files[0] | xss-through-dom.js:122:33:122:71 | URL.cre ... les[0]) |
227+
| xss-through-dom.js:122:53:122:70 | ev.target.files[0] | xss-through-dom.js:122:33:122:71 | URL.cre ... les[0]) |
219228
#select
220229
| 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 |
221230
| 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 |
@@ -252,3 +261,4 @@ edges
252261
| xss-through-dom.js:109:31:109:70 | "<a src ... oo</a>" | xss-through-dom.js:109:45:109:55 | this.el.src | xss-through-dom.js:109:31:109:70 | "<a src ... oo</a>" | $@ is reinterpreted as HTML without escaping meta-characters. | xss-through-dom.js:109:45:109:55 | this.el.src | DOM text |
253262
| xss-through-dom.js:115:16:115:18 | src | xss-through-dom.js:114:17:114:52 | documen ... k").src | xss-through-dom.js:115:16:115:18 | src | $@ is reinterpreted as HTML without escaping meta-characters. | xss-through-dom.js:114:17:114:52 | documen ... k").src | DOM text |
254263
| xss-through-dom.js:120:23:120:45 | ev.targ ... 0].name | xss-through-dom.js:120:23:120:37 | ev.target.files | xss-through-dom.js:120:23:120:45 | ev.targ ... 0].name | $@ is reinterpreted as HTML without escaping meta-characters. | xss-through-dom.js:120:23:120:37 | ev.target.files | DOM text |
264+
| xss-through-dom.js:122:33:122:71 | URL.cre ... les[0]) | xss-through-dom.js:122:53:122:67 | ev.target.files | xss-through-dom.js:122:33:122:71 | URL.cre ... les[0]) | $@ is reinterpreted as HTML without escaping meta-characters. | xss-through-dom.js:122:53:122:67 | ev.target.files | 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
@@ -118,5 +118,7 @@ class Sub extends Super {
118118

119119
$("input.foo")[0].onchange = function (ev) {
120120
$("#id").html(ev.target.files[0].name); // NOT OK.
121+
122+
$("img#id").attr("src", URL.createObjectURL(ev.target.files[0])); // NOT OK
121123
}
122124
})();

0 commit comments

Comments
 (0)