|
6 | 6 | private import python |
7 | 7 | private import TaintTrackingPrivate |
8 | 8 | private import experimental.dataflow.DataFlow |
9 | | -// /** |
10 | | -// * Holds if taint propagates from `source` to `sink` in zero or more local |
11 | | -// * (intra-procedural) steps. |
12 | | -// */ |
13 | | -// predicate localTaint(DataFlow::Node source, DataFlow::Node sink) { localTaintStep*(source, sink) } |
14 | | -// // /** |
15 | | -// // * Holds if taint can flow from `e1` to `e2` in zero or more |
16 | | -// // * local (intra-procedural) steps. |
17 | | -// // */ |
18 | | -// // predicate localExprTaint(Expr e1, Expr e2) { |
19 | | -// // localTaint(DataFlow::exprNode(e1), DataFlow::exprNode(e2)) |
20 | | -// // } |
21 | | -// // /** A member (property or field) that is tainted if its containing object is tainted. */ |
22 | | -// // abstract class TaintedMember extends AssignableMember { } |
23 | | -// /** |
24 | | -// * Holds if taint propagates from `nodeFrom` to `nodeTo` in exactly one local |
25 | | -// * (intra-procedural) step. |
26 | | -// */ |
27 | | -// predicate localTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { |
28 | | -// // Ordinary data flow |
29 | | -// DataFlow::localFlowStep(nodeFrom, nodeTo) |
30 | | -// or |
31 | | -// localAdditionalTaintStep(nodeFrom, nodeTo) |
32 | | -// } |
| 9 | + |
| 10 | +// Local taint flow and helpers |
| 11 | +/** |
| 12 | + * Holds if taint propagates from `source` to `sink` in zero or more local |
| 13 | + * (intra-procedural) steps. |
| 14 | + */ |
| 15 | +predicate localTaint(DataFlow::Node source, DataFlow::Node sink) { localTaintStep*(source, sink) } |
| 16 | + |
| 17 | +/** |
| 18 | + * Holds if taint can flow from `e1` to `e2` in zero or more local (intra-procedural) |
| 19 | + * steps. |
| 20 | + */ |
| 21 | +predicate localExprTaint(Expr e1, Expr e2) { |
| 22 | + localTaint(DataFlow::exprNode(e1), DataFlow::exprNode(e2)) |
| 23 | +} |
| 24 | + |
| 25 | +/** |
| 26 | + * Holds if taint propagates from `nodeFrom` to `nodeTo` in exactly one local |
| 27 | + * (intra-procedural) step. |
| 28 | + */ |
| 29 | +predicate localTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { |
| 30 | + // Ordinary data flow |
| 31 | + DataFlow::localFlowStep(nodeFrom, nodeTo) |
| 32 | + or |
| 33 | + localAdditionalTaintStep(nodeFrom, nodeTo) |
| 34 | +} |
| 35 | + |
| 36 | +// AdditionalTaintStep for global taint flow |
| 37 | +private newtype TUnit = TMkUnit() |
| 38 | + |
| 39 | +/** A singleton class containing a single dummy "unit" value. */ |
| 40 | +private class Unit extends TUnit { |
| 41 | + /** Gets a textual representation of this element. */ |
| 42 | + string toString() { result = "unit" } |
| 43 | +} |
| 44 | + |
| 45 | +/** |
| 46 | + * A unit class for adding additional taint steps. |
| 47 | + * |
| 48 | + * Extend this class to add additional taint steps that should apply to all |
| 49 | + * taint configurations. |
| 50 | + */ |
| 51 | +class AdditionalTaintStep extends Unit { |
| 52 | + /** |
| 53 | + * Holds if the step from `nodeFrom` to `nodeTo` should be considered a taint |
| 54 | + * step for all configurations. |
| 55 | + */ |
| 56 | + abstract predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo); |
| 57 | +} |
0 commit comments