Skip to content

Commit 2c89f97

Browse files
authored
Merge pull request github#12949 from asgerf/js/angular-native
JS: Add a few more DOM element sources
2 parents e9f1e99 + cf1e87d commit 2c89f97

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

javascript/ql/lib/semmle/javascript/DOM.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ module DOM {
421421
t.startInProp("target") and
422422
result = domEventSource()
423423
or
424+
t.startInProp(DataFlow::PseudoProperties::arrayElement()) and
425+
result = domElementCollection()
426+
or
424427
exists(DataFlow::TypeTracker t2 | result = domValueRef(t2).track(t2, t))
425428
}
426429

javascript/ql/lib/semmle/javascript/frameworks/Angular2.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,10 @@ module Angular2 {
547547
)
548548
}
549549
}
550+
551+
private class DomValueSources extends DOM::DomValueSource::Range {
552+
DomValueSources() {
553+
this = API::Node::ofType("@angular/core", "ElementRef").getMember("nativeElement").asSource()
554+
}
555+
}
550556
}

javascript/ql/test/library-tests/DOM/Customizations.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ test_documentRef
33
| event-handler-receiver.js:1:1:1:8 | document |
44
| event-handler-receiver.js:5:1:5:8 | document |
55
| nameditems.js:1:1:1:8 | document |
6+
| querySelectorAll.js:2:5:2:12 | document |
67
test_locationRef
78
| customization.js:3:3:3:14 | doc.location |
89
test_domValueRef
@@ -20,5 +21,8 @@ test_domValueRef
2021
| nameditems.js:1:1:1:23 | documen ... entById |
2122
| nameditems.js:1:1:1:30 | documen ... ('foo') |
2223
| nameditems.js:1:1:2:19 | documen ... em('x') |
24+
| querySelectorAll.js:2:5:2:29 | documen ... ctorAll |
25+
| querySelectorAll.js:2:5:2:36 | documen ... ('foo') |
26+
| querySelectorAll.js:2:46:2:48 | elm |
2327
| tst.js:49:3:49:8 | window |
2428
| tst.js:50:3:50:8 | window |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(function() {
2+
document.querySelectorAll('foo').forEach(elm => {
3+
elm.innerHTML = 'hey';
4+
});
5+
});

javascript/ql/test/library-tests/frameworks/Angular2/source.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from "@angular/core";
1+
import { Component,ElementRef } from "@angular/core";
22
import { DomSanitizer } from '@angular/platform-browser';
33

44
@Component({
@@ -9,6 +9,7 @@ export class Source {
99
taint: string;
1010
taintedArray: string[];
1111
safeArray: string[];
12+
elementRef: ElementRef;
1213

1314
constructor(private sanitizer: DomSanitizer) {
1415
this.taint = source();
@@ -18,5 +19,6 @@ export class Source {
1819

1920
methodOnComponent(x) {
2021
this.sanitizer.bypassSecurityTrustHtml(x);
22+
this.elementRef.nativeElement.innerHTML = x;
2123
}
2224
}

javascript/ql/test/library-tests/frameworks/Angular2/test.expected

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ pipeClassRef
2424
taintFlow
2525
| inline.component.ts:15:22:15:29 | source() | sink.component.ts:28:48:28:57 | this.sink7 |
2626
| inline.component.ts:15:22:15:29 | source() | sink.component.ts:30:48:30:57 | this.sink9 |
27-
| source.component.ts:14:22:14:29 | source() | TestPipe.ts:6:31:6:35 | value |
28-
| source.component.ts:14:22:14:29 | source() | sink.component.ts:22:48:22:57 | this.sink1 |
29-
| source.component.ts:14:22:14:29 | source() | sink.component.ts:25:48:25:57 | this.sink4 |
30-
| source.component.ts:14:22:14:29 | source() | sink.component.ts:26:48:26:57 | this.sink5 |
31-
| source.component.ts:14:22:14:29 | source() | sink.component.ts:27:48:27:57 | this.sink6 |
32-
| source.component.ts:14:22:14:29 | source() | sink.component.ts:29:48:29:57 | this.sink8 |
33-
| source.component.ts:14:22:14:29 | source() | source.component.ts:20:48:20:48 | x |
34-
| source.component.ts:15:33:15:40 | source() | sink.component.ts:22:48:22:57 | this.sink1 |
27+
| source.component.ts:15:22:15:29 | source() | TestPipe.ts:6:31:6:35 | value |
28+
| source.component.ts:15:22:15:29 | source() | sink.component.ts:22:48:22:57 | this.sink1 |
29+
| source.component.ts:15:22:15:29 | source() | sink.component.ts:25:48:25:57 | this.sink4 |
30+
| source.component.ts:15:22:15:29 | source() | sink.component.ts:26:48:26:57 | this.sink5 |
31+
| source.component.ts:15:22:15:29 | source() | sink.component.ts:27:48:27:57 | this.sink6 |
32+
| source.component.ts:15:22:15:29 | source() | sink.component.ts:29:48:29:57 | this.sink8 |
33+
| source.component.ts:15:22:15:29 | source() | source.component.ts:21:48:21:48 | x |
34+
| source.component.ts:15:22:15:29 | source() | source.component.ts:22:51:22:51 | x |
35+
| source.component.ts:16:33:16:40 | source() | sink.component.ts:22:48:22:57 | this.sink1 |
3536
testAttrSourceLocation
3637
| inline.component.ts:8:43:8:60 | [testAttr]=taint | inline.component.ts:8:55:8:59 | <toplevel> |

0 commit comments

Comments
 (0)