Skip to content

Commit b36075c

Browse files
committed
JS: step through refinements in AccessPaths
1 parent 720555b commit b36075c

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
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/TaintTracking/BasicTaintTracking.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
| access-path-sanitizer.js:2:18:2:25 | source() | access-path-sanitizer.js:4:8:4:12 | obj.x |
2-
| access-path-sanitizer.js:2:18:2:25 | source() | access-path-sanitizer.js:15:10:15:14 | obj.x |
32
| addexpr.js:4:10:4:17 | source() | addexpr.js:7:8:7:8 | x |
43
| addexpr.js:11:15:11:22 | source() | addexpr.js:21:8:21:12 | value |
54
| advanced-callgraph.js:2:13:2:20 | source() | advanced-callgraph.js:6:22:6:22 | v |

javascript/ql/test/library-tests/TaintTracking/access-path-sanitizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ function foo() {
1212
}
1313

1414
if (isSafe(obj.x) && typeof obj === "object") {
15-
sink(obj.x); // OK - but flagged anyway
15+
sink(obj.x); // OK
1616
}
1717
}

0 commit comments

Comments
 (0)