Skip to content

JS: add templates for forward and backwards data flow #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions javascript/src/audit/templates/BackwardsDataFlow.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @name Backwards Dataflow
* @description Backwards Dataflow (Note: backwards (partial) dataflow works differently in CodeQL for JavaScript, e.g. no PartialPathGraph is available.)
* @kind path-problem
* @precision low
* @problem.severity error
* @id githubsecuritylab/backwards-dataflow
* @tags template
*/

import javascript
import DataFlow::PathGraph
import semmle.javascript.explore.BackwardDataFlow

class BackwardDataFlowConfig extends TaintTracking::Configuration {
BackwardDataFlowConfig() { this = "BackwardDataFlowConfig" }

// `isSource` is ignored when `semmle.javascript.explore.BackwardDataFlow` is imported.

override predicate isSink(DataFlow::Node sink) {
// Define the sink to run the backwards dataflow from. Eg:
// sink = API::moduleImport("module").getMember("method").getParameter(0).asSink()
none()
}
}

from BackwardDataFlowConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "This node receives taint from $@.", source.getNode(),
"this source"

31 changes: 31 additions & 0 deletions javascript/src/audit/templates/ForwardDataFlow.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @name Forward Dataflow
* @description Forward Dataflow (Note: forward (partial) dataflow works differently in CodeQL for JavaScript, e.g. no PartialPathGraph is available.)
* @kind path-problem
* @precision low
* @problem.severity error
* @id githubsecuritylab/forward-dataflow
* @tags template
*/

import javascript
import DataFlow::PathGraph
import semmle.javascript.explore.ForwardDataFlow

class ForwardDataFlowConfig extends TaintTracking::Configuration {
ForwardDataFlowConfig() { this = "ForwardDataFlowConfig" }

override predicate isSource(DataFlow::Node source) {
// Define the source to run the forward dataflow from. Eg:
// source = API::moduleImport(_).getMember("method").getReturn().asSource()
none()
}

// `isSink` is ignored when `semmle.javascript.explore.ForwardDataFlow` is imported.
}

from ForwardDataFlowConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "This node receives taint from $@.", source.getNode(),
"this source"

Loading