Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90b3902

Browse files
author
Esben Sparre Andreasen
committed
JS: add a taint step for property projection
1 parent df97132 commit 90b3902

5 files changed

Lines changed: 61 additions & 0 deletions

File tree

javascript/ql/src/semmle/javascript/frameworks/PropertyProjection.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,22 @@ private class SimplePropertyProjection extends CustomPropertyProjection {
134134

135135
override predicate isSingletonProjection() { singleton = true }
136136

137+
}
138+
139+
/**
140+
* A taint step for a property projection.
141+
*/
142+
private class PropertyProjectionTaintStep extends TaintTracking::AdditionalTaintStep {
143+
144+
PropertyProjection projection;
145+
146+
PropertyProjectionTaintStep() {
147+
projection = this
148+
}
149+
150+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
151+
// reading from a tainted object yields a tainted result
152+
this = succ and
153+
pred = projection.getObject()
154+
}
137155
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| tst.js:25:10:25:15 | source |
2+
| tst.js:32:10:32:27 | _.pick(tainted, s) |
3+
| tst.js:33:10:33:26 | _.get(tainted, s) |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import javascript
2+
3+
class ExampleConfiguration extends TaintTracking::Configuration {
4+
5+
ExampleConfiguration() { this = "ExampleConfiguration" }
6+
7+
override predicate isSource(DataFlow::Node source) {
8+
source.asExpr().(CallExpr).getCalleeName() = "SOURCE"
9+
}
10+
11+
override predicate isSink(DataFlow::Node sink) {
12+
exists (CallExpr callExpr |
13+
callExpr.getCalleeName() = "SINK" and
14+
DataFlow::valueNode(callExpr.getArgument(0)) = sink
15+
)
16+
}
17+
18+
}
19+
20+
from ExampleConfiguration cfg, DataFlow::Node source, DataFlow::Node sink
21+
where cfg.hasFlow(source, sink)
22+
select sink

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
| tst.js:17:1:17:16 | dottie.get(o, s) | tst.js:17:12:17:12 | o | tst.js:17:15:17:15 | s | true |
1010
| tst.js:19:1:19:15 | dotty.get(o, s) | tst.js:19:11:19:11 | o | tst.js:19:14:19:14 | s | true |
1111
| tst.js:20:1:20:18 | dotty.search(o, s) | tst.js:20:14:20:14 | o | tst.js:20:17:20:17 | s | false |
12+
| tst.js:27:10:27:30 | _.pick( ... ted, s) | tst.js:27:17:27:26 | notTainted | tst.js:27:29:27:29 | s | false |
13+
| tst.js:28:10:28:29 | _.get(notTainted, s) | tst.js:28:16:28:25 | notTainted | tst.js:28:28:28:28 | s | true |
14+
| tst.js:32:10:32:27 | _.pick(tainted, s) | tst.js:32:17:32:23 | tainted | tst.js:32:26:32:26 | s | false |
15+
| tst.js:33:10:33:26 | _.get(tainted, s) | tst.js:33:16:33:22 | tainted | tst.js:33:25:33:25 | s | true |

javascript/ql/test/library-tests/frameworks/PropertyProjection/tst.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ dottie.get(o, s);
1818

1919
dotty.get(o, s);
2020
dotty.search(o, s);
21+
22+
(function(){
23+
var source = SOURCE();
24+
25+
SINK(source);
26+
27+
SINK(_.pick(notTainted, s));
28+
SINK(_.get(notTainted, s));
29+
30+
var tainted = {};
31+
tainted[x] = source;
32+
SINK(_.pick(tainted, s));
33+
SINK(_.get(tainted, s));
34+
});

0 commit comments

Comments
 (0)