Skip to content

Commit b3be197

Browse files
committed
JS: Fix attributes nodes missing an enclosing callable
1 parent 22b36a8 commit b3be197

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowPrivate.qll

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ class CastNode extends DataFlow::Node {
372372
cached
373373
newtype TDataFlowCallable =
374374
MkSourceCallable(StmtContainer container) or
375-
MkLibraryCallable(LibraryCallable callable)
375+
MkLibraryCallable(LibraryCallable callable) or
376+
MkFileCallable(File file)
376377

377378
/**
378379
* A callable entity. This is a wrapper around either a `StmtContainer` or a `LibraryCallable`.
@@ -383,14 +384,21 @@ class DataFlowCallable extends TDataFlowCallable {
383384
result = this.asSourceCallable().toString()
384385
or
385386
result = this.asLibraryCallable()
387+
or
388+
result = this.asFileCallable().toString()
386389
}
387390

388391
/** Gets the location of this callable, if it is present in the source code. */
389-
Location getLocation() { result = this.asSourceCallable().getLocation() }
392+
Location getLocation() {
393+
result = this.asSourceCallable().getLocation() or result = this.asFileCallable().getLocation()
394+
}
390395

391396
/** Gets the corresponding `StmtContainer` if this is a source callable. */
392397
StmtContainer asSourceCallable() { this = MkSourceCallable(result) }
393398

399+
/** Gets the corresponding `File` if this is a file representing a callable. */
400+
File asFileCallable() { this = MkFileCallable(result) }
401+
394402
/** Gets the corresponding `StmtContainer` if this is a source callable. */
395403
pragma[nomagic]
396404
StmtContainer asSourceCallableNotExterns() {
@@ -537,6 +545,10 @@ DataFlowCallable nodeGetEnclosingCallable(Node node) {
537545
result.asLibraryCallable() = node.(FlowSummaryDefaultExceptionalReturn).getSummarizedCallable()
538546
or
539547
node = TGenericSynthesizedNode(_, _, result)
548+
or
549+
node instanceof DataFlow::HtmlAttributeNode and result.asFileCallable() = node.getFile()
550+
or
551+
node instanceof DataFlow::XmlAttributeNode and result.asFileCallable() = node.getFile()
540552
}
541553

542554
newtype TDataFlowType =

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ nodes
607607
| typeahead.js:21:12:21:17 | target | semmle.label | target |
608608
| typeahead.js:24:30:24:32 | val | semmle.label | val |
609609
| typeahead.js:25:18:25:20 | val | semmle.label | val |
610+
| v-html.vue:2:8:2:23 | v-html=tainted | semmle.label | v-html=tainted |
611+
| v-html.vue:6:42:6:58 | document.location | semmle.label | document.location |
610612
| various-concat-obfuscations.js:2:6:2:39 | tainted | semmle.label | tainted |
611613
| various-concat-obfuscations.js:2:16:2:39 | documen ... .search | semmle.label | documen ... .search |
612614
| various-concat-obfuscations.js:4:4:4:31 | "<div>" ... </div>" | semmle.label | "<div>" ... </div>" |
@@ -1164,6 +1166,7 @@ edges
11641166
| typeahead.js:20:22:20:45 | documen ... .search | typeahead.js:20:13:20:45 | target | provenance | |
11651167
| typeahead.js:21:12:21:17 | target | typeahead.js:24:30:24:32 | val | provenance | |
11661168
| typeahead.js:24:30:24:32 | val | typeahead.js:25:18:25:20 | val | provenance | |
1169+
| v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted | provenance | |
11671170
| various-concat-obfuscations.js:2:6:2:39 | tainted | various-concat-obfuscations.js:4:14:4:20 | tainted | provenance | |
11681171
| various-concat-obfuscations.js:2:6:2:39 | tainted | various-concat-obfuscations.js:5:12:5:18 | tainted | provenance | |
11691172
| various-concat-obfuscations.js:2:6:2:39 | tainted | various-concat-obfuscations.js:6:19:6:25 | tainted | provenance | |
@@ -1453,6 +1456,7 @@ subpaths
14531456
| tst.js:501:33:501:63 | decodeU ... n.hash) | tst.js:501:43:501:62 | window.location.hash | tst.js:501:33:501:63 | decodeU ... n.hash) | Cross-site scripting vulnerability due to $@. | tst.js:501:43:501:62 | window.location.hash | user-provided value |
14541457
| tst.js:509:18:509:54 | target. ... "), '') | tst.js:508:16:508:39 | documen ... .search | tst.js:509:18:509:54 | target. ... "), '') | Cross-site scripting vulnerability due to $@. | tst.js:508:16:508:39 | documen ... .search | user-provided value |
14551458
| typeahead.js:25:18:25:20 | val | typeahead.js:20:22:20:45 | documen ... .search | typeahead.js:25:18:25:20 | val | Cross-site scripting vulnerability due to $@. | typeahead.js:20:22:20:45 | documen ... .search | user-provided value |
1459+
| v-html.vue:2:8:2:23 | v-html=tainted | v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted | Cross-site scripting vulnerability due to $@. | v-html.vue:6:42:6:58 | document.location | user-provided value |
14561460
| various-concat-obfuscations.js:4:4:4:31 | "<div>" ... </div>" | various-concat-obfuscations.js:2:16:2:39 | documen ... .search | various-concat-obfuscations.js:4:4:4:31 | "<div>" ... </div>" | Cross-site scripting vulnerability due to $@. | various-concat-obfuscations.js:2:16:2:39 | documen ... .search | user-provided value |
14571461
| various-concat-obfuscations.js:5:4:5:26 | `<div>$ ... </div>` | various-concat-obfuscations.js:2:16:2:39 | documen ... .search | various-concat-obfuscations.js:5:4:5:26 | `<div>$ ... </div>` | Cross-site scripting vulnerability due to $@. | various-concat-obfuscations.js:2:16:2:39 | documen ... .search | user-provided value |
14581462
| various-concat-obfuscations.js:6:4:6:43 | "<div>" ... /div>") | various-concat-obfuscations.js:2:16:2:39 | documen ... .search | various-concat-obfuscations.js:6:4:6:43 | "<div>" ... /div>") | Cross-site scripting vulnerability due to $@. | various-concat-obfuscations.js:2:16:2:39 | documen ... .search | user-provided value |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ nodes
614614
| typeahead.js:21:12:21:17 | target | semmle.label | target |
615615
| typeahead.js:24:30:24:32 | val | semmle.label | val |
616616
| typeahead.js:25:18:25:20 | val | semmle.label | val |
617+
| v-html.vue:2:8:2:23 | v-html=tainted | semmle.label | v-html=tainted |
618+
| v-html.vue:6:42:6:58 | document.location | semmle.label | document.location |
617619
| various-concat-obfuscations.js:2:6:2:39 | tainted | semmle.label | tainted |
618620
| various-concat-obfuscations.js:2:16:2:39 | documen ... .search | semmle.label | documen ... .search |
619621
| various-concat-obfuscations.js:4:4:4:31 | "<div>" ... </div>" | semmle.label | "<div>" ... </div>" |
@@ -1189,6 +1191,7 @@ edges
11891191
| typeahead.js:20:22:20:45 | documen ... .search | typeahead.js:20:13:20:45 | target | provenance | |
11901192
| typeahead.js:21:12:21:17 | target | typeahead.js:24:30:24:32 | val | provenance | |
11911193
| typeahead.js:24:30:24:32 | val | typeahead.js:25:18:25:20 | val | provenance | |
1194+
| v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted | provenance | |
11921195
| various-concat-obfuscations.js:2:6:2:39 | tainted | various-concat-obfuscations.js:4:14:4:20 | tainted | provenance | |
11931196
| various-concat-obfuscations.js:2:6:2:39 | tainted | various-concat-obfuscations.js:5:12:5:18 | tainted | provenance | |
11941197
| various-concat-obfuscations.js:2:6:2:39 | tainted | various-concat-obfuscations.js:6:19:6:25 | tainted | provenance | |

0 commit comments

Comments
 (0)