Skip to content

Commit 8599ab2

Browse files
committed
JS: Fix attributes nodes missing an enclosing callable
1 parent 087c555 commit 8599ab2

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,25 +372,33 @@ 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
/**
378-
* A callable entity. This is a wrapper around either a `StmtContainer` or a `LibraryCallable`.
379+
* A callable entity. This is a wrapper around either a `StmtContainer`, `LibraryCallable`, or `File`.
379380
*/
380381
class DataFlowCallable extends TDataFlowCallable {
381382
/** Gets a string representation of this callable. */
382383
string toString() {
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
@@ -224,6 +224,7 @@
224224
| tst.js:484:33:484:63 | decodeU ... n.hash) | tst.js:484:43:484:62 | window.location.hash | tst.js:484:33:484:63 | decodeU ... n.hash) | Cross-site scripting vulnerability due to $@. | tst.js:484:43:484:62 | window.location.hash | user-provided value |
225225
| tst.js:492:18:492:54 | target. ... "), '') | tst.js:491:16:491:39 | documen ... .search | tst.js:492:18:492:54 | target. ... "), '') | Cross-site scripting vulnerability due to $@. | tst.js:491:16:491:39 | documen ... .search | user-provided value |
226226
| 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 |
227+
| 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 |
227228
| 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 |
228229
| 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 |
229230
| 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 |
@@ -748,6 +749,7 @@ edges
748749
| typeahead.js:20:22:20:45 | documen ... .search | typeahead.js:20:13:20:45 | target | provenance | |
749750
| typeahead.js:21:12:21:17 | target | typeahead.js:24:30:24:32 | val | provenance | |
750751
| typeahead.js:24:30:24:32 | val | typeahead.js:25:18:25:20 | val | provenance | |
752+
| v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted | provenance | |
751753
| various-concat-obfuscations.js:2:6:2:39 | tainted | various-concat-obfuscations.js:4:14:4:20 | tainted | provenance | |
752754
| various-concat-obfuscations.js:2:6:2:39 | tainted | various-concat-obfuscations.js:5:12:5:18 | tainted | provenance | |
753755
| various-concat-obfuscations.js:2:6:2:39 | tainted | various-concat-obfuscations.js:6:19:6:25 | tainted | provenance | |
@@ -1400,6 +1402,8 @@ nodes
14001402
| typeahead.js:21:12:21:17 | target | semmle.label | target |
14011403
| typeahead.js:24:30:24:32 | val | semmle.label | val |
14021404
| typeahead.js:25:18:25:20 | val | semmle.label | val |
1405+
| v-html.vue:2:8:2:23 | v-html=tainted | semmle.label | v-html=tainted |
1406+
| v-html.vue:6:42:6:58 | document.location | semmle.label | document.location |
14031407
| various-concat-obfuscations.js:2:6:2:39 | tainted | semmle.label | tainted |
14041408
| various-concat-obfuscations.js:2:16:2:39 | documen ... .search | semmle.label | documen ... .search |
14051409
| various-concat-obfuscations.js:4:4:4:31 | "<div>" ... </div>" | semmle.label | "<div>" ... </div>" |

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 | |

javascript/ql/test/query-tests/Security/CWE-079/DomBasedXss/v-html.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
2-
<p v-html="tainted"/>
2+
<p v-html="tainted"/> <!-- $ Alert -->
33
</template>
44
<script>
55
export default {
6-
data: function() { return { tainted: document.location } }
6+
data: function() { return { tainted: document.location } } // $ Source
77
}
88
</script>
99
<style>

0 commit comments

Comments
 (0)