Skip to content

Commit d7ea57c

Browse files
authored
Merge pull request #56 from GitHubSecurityLab/p--js-dataflow
JS: add templates for forward and backwards data flow
2 parents 00d0be2 + 85b6d61 commit d7ea57c

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @name Backwards Dataflow
3+
* @description Backwards Dataflow (Note: backwards (partial) dataflow works differently in CodeQL for JavaScript, e.g. no PartialPathGraph is available.)
4+
* @kind path-problem
5+
* @precision low
6+
* @problem.severity error
7+
* @id githubsecuritylab/backwards-dataflow
8+
* @tags template
9+
*/
10+
11+
import javascript
12+
import DataFlow::PathGraph
13+
import semmle.javascript.explore.BackwardDataFlow
14+
15+
class BackwardDataFlowConfig extends TaintTracking::Configuration {
16+
BackwardDataFlowConfig() { this = "BackwardDataFlowConfig" }
17+
18+
// `isSource` is ignored when `semmle.javascript.explore.BackwardDataFlow` is imported.
19+
20+
override predicate isSink(DataFlow::Node sink) {
21+
// Define the sink to run the backwards dataflow from. Eg:
22+
// sink = API::moduleImport("module").getMember("method").getParameter(0).asSink()
23+
none()
24+
}
25+
}
26+
27+
from BackwardDataFlowConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
28+
where cfg.hasFlowPath(source, sink)
29+
select sink.getNode(), source, sink, "This node receives taint from $@.", source.getNode(),
30+
"this source"
31+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @name Forward Dataflow
3+
* @description Forward Dataflow (Note: forward (partial) dataflow works differently in CodeQL for JavaScript, e.g. no PartialPathGraph is available.)
4+
* @kind path-problem
5+
* @precision low
6+
* @problem.severity error
7+
* @id githubsecuritylab/forward-dataflow
8+
* @tags template
9+
*/
10+
11+
import javascript
12+
import DataFlow::PathGraph
13+
import semmle.javascript.explore.ForwardDataFlow
14+
15+
class ForwardDataFlowConfig extends TaintTracking::Configuration {
16+
ForwardDataFlowConfig() { this = "ForwardDataFlowConfig" }
17+
18+
override predicate isSource(DataFlow::Node source) {
19+
// Define the source to run the forward dataflow from. Eg:
20+
// source = API::moduleImport(_).getMember("method").getReturn().asSource()
21+
none()
22+
}
23+
24+
// `isSink` is ignored when `semmle.javascript.explore.ForwardDataFlow` is imported.
25+
}
26+
27+
from ForwardDataFlowConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
28+
where cfg.hasFlowPath(source, sink)
29+
select sink.getNode(), source, sink, "This node receives taint from $@.", source.getNode(),
30+
"this source"
31+

0 commit comments

Comments
 (0)