|
| 1 | +import python |
| 2 | +import semmle.python.security.TaintTracking |
| 3 | + |
| 4 | +module TaintTracking { |
| 5 | + |
| 6 | + class Source = TaintSource; |
| 7 | + |
| 8 | + class Sink = TaintSink; |
| 9 | + |
| 10 | + class PathSource = TaintedPathSource; |
| 11 | + |
| 12 | + class PathSink = TaintedPathSink; |
| 13 | + |
| 14 | + class Extension = DataFlowExtension::DataFlowNode; |
| 15 | + |
| 16 | + abstract class Configuration extends string { |
| 17 | + |
| 18 | + /* Required to prevent compiler warning */ |
| 19 | + bindingset[this] |
| 20 | + Configuration() { this = this } |
| 21 | + |
| 22 | + /* Old implementation API */ |
| 23 | + |
| 24 | + predicate isSource(Source source) { none() } |
| 25 | + |
| 26 | + predicate isSink(Sink sink) { none() } |
| 27 | + |
| 28 | + predicate isSanitizer(Sanitizer sanitizer) { none() } |
| 29 | + |
| 30 | + predicate isExtension(Extension extension) { none() } |
| 31 | + |
| 32 | + /* New implementation API */ |
| 33 | + |
| 34 | + /** |
| 35 | + * Holds if `source` is a source of taint of `kind` that is relevant |
| 36 | + * for this configuration. |
| 37 | + */ |
| 38 | + predicate isSource(DataFlow::Node source, TaintKind kind) { none() } |
| 39 | + |
| 40 | + /** |
| 41 | + * Holds if `sink` is a sink of taint of `kind` that is relevant |
| 42 | + * for this configuration. |
| 43 | + */ |
| 44 | + predicate isSink(DataFlow::Node sink, TaintKind kind) { none() } |
| 45 | + |
| 46 | + /** |
| 47 | + * Holds if `src -> dest` should be considered as a flow edge |
| 48 | + * in addition to standard data flow edges. |
| 49 | + */ |
| 50 | + predicate isAdditionalFlowStep(DataFlow::Node src, DataFlow::Node dest) { none() } |
| 51 | + |
| 52 | + /** |
| 53 | + * Holds if `src -> dest` is a flow edge converting taint from `srckind` to `destkind`. |
| 54 | + */ |
| 55 | + predicate isAdditionalFlowStep(DataFlow::Node src, DataFlow::Node trg, TaintKind srckind, TaintKind destkind) { |
| 56 | + none() |
| 57 | + } |
| 58 | + |
| 59 | + predicate isBarrier(DataFlow::Node node) { none() } |
| 60 | + |
| 61 | + predicate isBarrier(DataFlow::Node node, TaintKind kind) { none() } |
| 62 | + |
| 63 | + /** |
| 64 | + * Holds if flow from `src` to `dest` is prohibited. |
| 65 | + */ |
| 66 | + predicate isBarrierEdge(DataFlow::Node src, DataFlow::Node trg) { none() } |
| 67 | + |
| 68 | + /** |
| 69 | + * Holds if flow from `src` to `dest` is prohibited when the incoming taint is `srckind` and the outgoing taint is `destkind`. |
| 70 | + * Note that `srckind` and `destkind` can be the same. |
| 71 | + */ |
| 72 | + predicate isBarrierEdge(DataFlow::Node src, DataFlow::Node dest, TaintKind srckind, TaintKind destkind) { none() } |
| 73 | + |
| 74 | + /* Common query API */ |
| 75 | + |
| 76 | + predicate hasFlowPath(PathSource source, PathSink sink) { |
| 77 | + this.isSource(source.getNode()) and |
| 78 | + this.isSink(sink.getNode()) and |
| 79 | + source.flowsTo(sink) |
| 80 | + } |
| 81 | + |
| 82 | + /* Old query API */ |
| 83 | + |
| 84 | + deprecated predicate hasFlow(Source source, Sink sink) { |
| 85 | + exists(PathSource psource, PathSink psink | |
| 86 | + this.hasFlowPath(psource, psink) and |
| 87 | + source = psource.getCfgNode() and |
| 88 | + sink = psink.getCfgNode() |
| 89 | + ) |
| 90 | + } |
| 91 | + |
| 92 | + /* New query API */ |
| 93 | + |
| 94 | + predicate hasSimpleFlow(DataFlow::Node source, DataFlow::Node sink) { |
| 95 | + /* TO DO */ |
| 96 | + exists(PathSource psource, PathSink psink | |
| 97 | + this.hasFlowPath(psource, psink) and |
| 98 | + source = psource.getNode() and |
| 99 | + sink = psink.getNode() |
| 100 | + ) |
| 101 | + } |
| 102 | + |
| 103 | + } |
| 104 | + |
| 105 | +} |
| 106 | + |
0 commit comments