Skip to content

Commit 10130ee

Browse files
authored
Merge pull request github#8678 from erik-krogh/fileSource
JS: Add files as a source for `js/xss-through-dom`
2 parents 2fb3147 + 0435cee commit 10130ee

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ module XssThroughDom {
162162
}
163163
}
164164

165+
/** The `files` property of an `<input />` element */
166+
class FilesSource extends Source {
167+
FilesSource() { this = DOM::domValueRef().getAPropertyRead("files") }
168+
}
169+
165170
/**
166171
* A module for form inputs seen as sources for xss-through-dom.
167172
*/

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ nodes
129129
| xss-through-dom.js:115:16:115:18 | src |
130130
| xss-through-dom.js:117:26:117:28 | src |
131131
| xss-through-dom.js:117:26:117:28 | src |
132+
| xss-through-dom.js:120:23:120:37 | ev.target.files |
133+
| xss-through-dom.js:120:23:120:37 | ev.target.files |
134+
| xss-through-dom.js:120:23:120:40 | ev.target.files[0] |
135+
| xss-through-dom.js:120:23:120:45 | ev.targ ... 0].name |
136+
| 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] |
132142
edges
133143
| forms.js:8:23:8:28 | values | forms.js:9:31:9:36 | values |
134144
| forms.js:8:23:8:28 | values | forms.js:9:31:9:36 | values |
@@ -207,6 +217,14 @@ edges
207217
| xss-through-dom.js:114:11:114:52 | src | xss-through-dom.js:117:26:117:28 | src |
208218
| xss-through-dom.js:114:17:114:52 | documen ... k").src | xss-through-dom.js:114:11:114:52 | src |
209219
| xss-through-dom.js:114:17:114:52 | documen ... k").src | xss-through-dom.js:114:11:114:52 | src |
220+
| xss-through-dom.js:120:23:120:37 | ev.target.files | xss-through-dom.js:120:23:120:40 | ev.target.files[0] |
221+
| xss-through-dom.js:120:23:120:37 | ev.target.files | xss-through-dom.js:120:23:120:40 | ev.target.files[0] |
222+
| xss-through-dom.js:120:23:120:40 | ev.target.files[0] | xss-through-dom.js:120:23:120:45 | ev.targ ... 0].name |
223+
| 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]) |
210228
#select
211229
| 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 |
212230
| 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 |
@@ -242,3 +260,5 @@ edges
242260
| xss-through-dom.js:96:17:96:47 | $("#foo ... ].value | xss-through-dom.js:96:17:96:47 | $("#foo ... ].value | xss-through-dom.js:96:17:96:47 | $("#foo ... ].value | $@ is reinterpreted as HTML without escaping meta-characters. | xss-through-dom.js:96:17:96:47 | $("#foo ... ].value | DOM text |
243261
| 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 |
244262
| 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 |
263+
| 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,10 @@ class Sub extends Super {
115115
$("#id").html(src); // NOT OK.
116116

117117
$("#id").attr("src", src); // OK
118+
119+
$("input.foo")[0].onchange = function (ev) {
120+
$("#id").html(ev.target.files[0].name); // NOT OK.
121+
122+
$("img#id").attr("src", URL.createObjectURL(ev.target.files[0])); // NOT OK
123+
}
118124
})();

0 commit comments

Comments
 (0)