Skip to content

Commit 61f7c78

Browse files
authored
Merge pull request #1421 from xiemaisi/js/data-flow-tutorial-tests
Approved by esben-semmle
2 parents 831850f + 398ee0c commit 61f7c78

File tree

23 files changed

+235
-0
lines changed

23 files changed

+235
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test1.js:13:16:13:30 | process.argv[2] | test1.js:6:15:6:15 | p |
2+
| test2.js:20:16:20:30 | process.argv[2] | test2.js:13:15:13:15 | p |
3+
| test3.js:19:16:19:30 | process.argv[2] | test3.js:12:15:12:15 | p |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import javascript
2+
3+
class CommandLineFileNameConfiguration extends TaintTracking::Configuration {
4+
CommandLineFileNameConfiguration() { this = "CommandLineFileNameConfiguration" }
5+
6+
override predicate isSource(DataFlow::Node source) {
7+
DataFlow::globalVarRef("process").getAPropertyRead("argv").getAPropertyRead() = source
8+
}
9+
10+
override predicate isSink(DataFlow::Node sink) {
11+
DataFlow::moduleMember("fs", "readFile").getACall().getArgument(0) = sink
12+
}
13+
}
14+
15+
from CommandLineFileNameConfiguration cfg, DataFlow::Node source, DataFlow::Node sink
16+
where cfg.hasFlow(source, sink)
17+
select source, sink
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test1.js:13:16:13:30 | process.argv[2] | test1.js:6:15:6:15 | p |
2+
| test3.js:19:16:19:30 | process.argv[2] | test3.js:12:15:12:15 | p |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import javascript
2+
3+
class CommandLineFileNameConfiguration extends TaintTracking::Configuration {
4+
CommandLineFileNameConfiguration() { this = "CommandLineFileNameConfiguration" }
5+
6+
override predicate isSource(DataFlow::Node source) {
7+
DataFlow::globalVarRef("process").getAPropertyRead("argv").getAPropertyRead() = source
8+
}
9+
10+
override predicate isSink(DataFlow::Node sink) {
11+
DataFlow::moduleMember("fs", "readFile").getACall().getArgument(0) = sink
12+
}
13+
14+
override predicate isSanitizer(DataFlow::Node nd) {
15+
nd.(DataFlow::CallNode).getCalleeName() = "checkPath"
16+
}
17+
}
18+
19+
from CommandLineFileNameConfiguration cfg, DataFlow::Node source, DataFlow::Node sink
20+
where cfg.hasFlow(source, sink)
21+
select source, sink
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test1.js:13:16:13:30 | process.argv[2] | test1.js:6:15:6:15 | p |
2+
| test2.js:20:16:20:30 | process.argv[2] | test2.js:13:15:13:15 | p |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import javascript
2+
3+
class CheckPathSanitizerGuard extends TaintTracking::SanitizerGuardNode, DataFlow::CallNode {
4+
CheckPathSanitizerGuard() { this.getCalleeName() = "checkPath" }
5+
6+
override predicate sanitizes(boolean outcome, Expr e) {
7+
outcome = true and
8+
e = getArgument(0).asExpr()
9+
}
10+
}
11+
12+
class CommandLineFileNameConfiguration extends TaintTracking::Configuration {
13+
CommandLineFileNameConfiguration() { this = "CommandLineFileNameConfiguration" }
14+
15+
override predicate isSource(DataFlow::Node source) {
16+
DataFlow::globalVarRef("process").getAPropertyRead("argv").getAPropertyRead() = source
17+
}
18+
19+
override predicate isSink(DataFlow::Node sink) {
20+
DataFlow::moduleMember("fs", "readFile").getACall().getArgument(0) = sink
21+
}
22+
23+
override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode nd) {
24+
nd instanceof CheckPathSanitizerGuard
25+
}
26+
}
27+
28+
from CommandLineFileNameConfiguration cfg, DataFlow::Node source, DataFlow::Node sink
29+
where cfg.hasFlow(source, sink)
30+
select source, sink
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test1.js:13:16:13:30 | process.argv[2] | test1.js:6:15:6:15 | p |
2+
| test2.js:20:16:20:30 | process.argv[2] | test2.js:13:15:13:15 | p |
3+
| test3.js:19:16:19:30 | process.argv[2] | test3.js:12:15:12:15 | p |
4+
| test4.js:14:16:14:30 | process.argv[2] | test4.js:7:13:7:13 | p |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import javascript
2+
3+
class CommandLineFileNameConfiguration extends TaintTracking::Configuration {
4+
CommandLineFileNameConfiguration() { this = "CommandLineFileNameConfiguration" }
5+
6+
override predicate isSource(DataFlow::Node source) {
7+
DataFlow::globalVarRef("process").getAPropertyRead("argv").getAPropertyRead() = source
8+
}
9+
10+
override predicate isSink(DataFlow::Node sink) {
11+
DataFlow::moduleMember("fs", "readFile").getACall().getArgument(0) = sink
12+
}
13+
14+
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
15+
exists(DataFlow::CallNode c |
16+
c = DataFlow::moduleImport("resolve-symlinks").getACall() and
17+
pred = c.getArgument(0) and
18+
succ = c
19+
)
20+
}
21+
}
22+
23+
from CommandLineFileNameConfiguration cfg, DataFlow::Node source, DataFlow::Node sink
24+
where cfg.hasFlow(source, sink)
25+
select source, sink
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test1.js:13:16:13:30 | process.argv[2] | test1.js:6:15:6:15 | p |
2+
| test2.js:20:16:20:30 | process.argv[2] | test2.js:13:15:13:15 | p |
3+
| test3.js:19:16:19:30 | process.argv[2] | test3.js:12:15:12:15 | p |
4+
| test4.js:14:16:14:30 | process.argv[2] | test4.js:7:13:7:13 | p |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import javascript
2+
3+
class StepThroughResolveSymlinks extends TaintTracking::AdditionalTaintStep, DataFlow::CallNode {
4+
StepThroughResolveSymlinks() { this = DataFlow::moduleImport("resolve-symlinks").getACall() }
5+
6+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
7+
pred = this.getArgument(0) and
8+
succ = this
9+
}
10+
}
11+
12+
class CommandLineFileNameConfiguration extends TaintTracking::Configuration {
13+
CommandLineFileNameConfiguration() { this = "CommandLineFileNameConfiguration" }
14+
15+
override predicate isSource(DataFlow::Node source) {
16+
DataFlow::globalVarRef("process").getAPropertyRead("argv").getAPropertyRead() = source
17+
}
18+
19+
override predicate isSink(DataFlow::Node sink) {
20+
DataFlow::moduleMember("fs", "readFile").getACall().getArgument(0) = sink
21+
}
22+
}
23+
24+
from CommandLineFileNameConfiguration cfg, DataFlow::Node source, DataFlow::Node sink
25+
where cfg.hasFlow(source, sink)
26+
select source, sink

0 commit comments

Comments
 (0)