|
| 1 | +/** |
| 2 | + * Provides machinery for performing backward data-flow exploration. |
| 3 | + * |
| 4 | + * Importing this module effectively makes all data-flow and taint-tracking configurations |
| 5 | + * ignore their `isSource` predicate. Instead, flow is tracked from any _initial node_ (that is, |
| 6 | + * a node without incoming flow) to a sink node. All initial nodes are then treated as source |
| 7 | + * nodes. |
| 8 | + * |
| 9 | + * Data-flow exploration cannot be used with configurations depending on other configurations. |
| 10 | + * |
| 11 | + * NOTE: This library should only be used for debugging, not in production code. Backward |
| 12 | + * exploration in particular does not scale on non-trivial code bases and hence is of limited |
| 13 | + * usefulness as it stands. |
| 14 | + */ |
| 15 | + |
| 16 | +import javascript |
| 17 | + |
| 18 | +private class BackwardExploringConfiguration extends DataFlow::Configuration { |
| 19 | + DataFlow::Configuration cfg; |
| 20 | + |
| 21 | + BackwardExploringConfiguration() { |
| 22 | + this = cfg |
| 23 | + } |
| 24 | + |
| 25 | + override predicate isSource(DataFlow::Node node) { any() } |
| 26 | + |
| 27 | + override predicate isSource(DataFlow::Node node, DataFlow::FlowLabel lbl) { any() } |
| 28 | + |
| 29 | + override predicate hasFlow(DataFlow::Node source, DataFlow::Node sink) { |
| 30 | + exists(DataFlow::PathNode src, DataFlow::PathNode snk | hasFlowPath(src, snk) | |
| 31 | + source = src.getNode() and |
| 32 | + sink = snk.getNode() |
| 33 | + ) |
| 34 | + } |
| 35 | + |
| 36 | + override predicate hasFlowPath(DataFlow::SourcePathNode source, DataFlow::SinkPathNode sink) { |
| 37 | + exists(DataFlow::MidPathNode first | |
| 38 | + source.getConfiguration() = this and |
| 39 | + source.getASuccessor() = first and |
| 40 | + not exists(DataFlow::MidPathNode mid | mid.getASuccessor() = first) and |
| 41 | + first.getASuccessor*() = sink |
| 42 | + ) |
| 43 | + } |
| 44 | +} |
0 commit comments