Skip to content

Commit ff25a3e

Browse files
authored
Merge pull request #1243 from asger-semmle/access-path-refinements
Approved by xiemaisi
2 parents 65e508a + b8ec708 commit ff25a3e

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

javascript/ql/src/semmle/javascript/dataflow/internal/AccessPaths.qll

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,23 @@ private PropertyName getPropertyName(PropAccess pacc) {
3939
)
4040
}
4141

42+
private SsaVariable getRefinedVariable(SsaVariable variable) {
43+
result = variable.getDefinition().(SsaRefinementNode).getAnInput()
44+
}
45+
46+
private SsaVariable getARefinementOf(SsaVariable variable) {
47+
variable = getRefinedVariable(result)
48+
}
49+
4250
/**
4351
* A representation of a (nested) property access on an SSA variable
4452
* where each property name is either constant or itself an SSA variable.
4553
*/
4654
private newtype TAccessPath =
47-
MkSsaRoot(SsaVariable var) or
55+
MkSsaRoot(SsaVariable var) {
56+
not exists(getRefinedVariable(var))
57+
}
58+
or
4859
MkThisRoot(Function function) { function.getThisBinder() = function } or
4960
MkAccessStep(AccessPath base, PropertyName name) {
5061
exists(PropAccess pacc |
@@ -64,7 +75,7 @@ class AccessPath extends TAccessPath {
6475
Expr getAnInstanceIn(BasicBlock bb) {
6576
exists(SsaVariable var |
6677
this = MkSsaRoot(var) and
67-
result = var.getAUseIn(bb)
78+
result = getARefinementOf*(var).getAUseIn(bb)
6879
)
6980
or
7081
exists(ThisExpr this_ |

javascript/ql/test/library-tests/TaintBarriers/isBarrier.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
| tst.js:134:14:134:16 | v.p | ExampleConfiguration |
1818
| tst.js:136:14:136:18 | v.p.q | ExampleConfiguration |
1919
| tst.js:148:9:148:27 | v | ExampleConfiguration |
20+
| tst.js:149:14:149:14 | v | ExampleConfiguration |
2021
| tst.js:154:9:154:27 | v | ExampleConfiguration |
22+
| tst.js:157:14:157:14 | v | ExampleConfiguration |
2123
| tst.js:160:9:160:30 | v | ExampleConfiguration |
2224
| tst.js:160:35:160:56 | v | ExampleConfiguration |
2325
| tst.js:167:14:167:14 | v | ExampleConfiguration |
@@ -36,6 +38,7 @@
3638
| tst.js:284:14:284:14 | v | ExampleConfiguration |
3739
| tst.js:331:14:331:14 | v | ExampleConfiguration |
3840
| tst.js:356:16:356:27 | x10 | ExampleConfiguration |
41+
| tst.js:356:32:356:34 | x10 | ExampleConfiguration |
3942
| tst.js:361:14:361:14 | v | ExampleConfiguration |
4043
| tst.js:371:14:371:16 | o.p | ExampleConfiguration |
4144
| tst.js:378:14:378:17 | o[p] | ExampleConfiguration |

javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| access-path-sanitizer.js:2:18:2:25 | source() | access-path-sanitizer.js:4:8:4:12 | obj.x |
12
| addexpr.js:4:10:4:17 | source() | addexpr.js:7:8:7:8 | x |
23
| addexpr.js:11:15:11:22 | source() | addexpr.js:21:8:21:12 | value |
34
| advanced-callgraph.js:2:13:2:20 | source() | advanced-callgraph.js:6:22:6:22 | v |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function foo() {
2+
let obj = { x: source() };
3+
4+
sink(obj.x); // NOT OK
5+
6+
if (isSafe(obj.x)) {
7+
sink(obj.x); // OK
8+
}
9+
10+
if (typeof obj === "object" && isSafe(obj.x)) {
11+
sink(obj.x); // OK
12+
}
13+
14+
if (isSafe(obj.x) && typeof obj === "object") {
15+
sink(obj.x); // OK
16+
}
17+
}

0 commit comments

Comments
 (0)