|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `multidict` PyPI package. |
| 3 | + * See https://multidict.readthedocs.io/en/stable/. |
| 4 | + */ |
| 5 | + |
| 6 | +private import python |
| 7 | +private import semmle.python.dataflow.new.DataFlow |
| 8 | +private import semmle.python.dataflow.new.TaintTracking |
| 9 | +private import semmle.python.Concepts |
| 10 | +private import semmle.python.ApiGraphs |
| 11 | + |
| 12 | +/** |
| 13 | + * INTERNAL: Do not use. |
| 14 | + * |
| 15 | + * Provides models for the `multidict` PyPI package. |
| 16 | + * See https://multidict.readthedocs.io/en/stable/. |
| 17 | + */ |
| 18 | +module Multidict { |
| 19 | + /** |
| 20 | + * Provides models for a `MultiDictProxy` class: |
| 21 | + * - `multidict.MultiDictProxy` |
| 22 | + * - `multidict.CIMultiDictProxy` |
| 23 | + * |
| 24 | + * See https://multidict.readthedocs.io/en/stable/multidict.html#multidictproxy |
| 25 | + */ |
| 26 | + module MultiDictProxy { |
| 27 | + /** |
| 28 | + * A source of instances of `multidict.MultiDictProxy`, extend this class to model |
| 29 | + * new instances. |
| 30 | + * |
| 31 | + * This can include instantiations of the class, return values from function |
| 32 | + * calls, or a special parameter that will be set when functions are called by an external |
| 33 | + * library. |
| 34 | + * |
| 35 | + * Use `MultiDictProxy::instance()` predicate to get |
| 36 | + * references to instances of `multidict.MultiDictProxy`. |
| 37 | + */ |
| 38 | + abstract class InstanceSource extends DataFlow::LocalSourceNode { } |
| 39 | + |
| 40 | + /** Gets a reference to an instance of `multidict.MultiDictProxy`. */ |
| 41 | + private DataFlow::LocalSourceNode instance(DataFlow::TypeTracker t) { |
| 42 | + t.start() and |
| 43 | + result instanceof InstanceSource |
| 44 | + or |
| 45 | + exists(DataFlow::TypeTracker t2 | result = instance(t2).track(t2, t)) |
| 46 | + } |
| 47 | + |
| 48 | + /** Gets a reference to an instance of `multidict.MultiDictProxy`. */ |
| 49 | + DataFlow::Node instance() { instance(DataFlow::TypeTracker::end()).flowsTo(result) } |
| 50 | + |
| 51 | + /** |
| 52 | + * Taint propagation for `multidict.MultiDictProxy`. |
| 53 | + * |
| 54 | + * See https://multidict.readthedocs.io/en/stable/multidict.html#multidictproxy |
| 55 | + */ |
| 56 | + class MultiDictProxyAdditionalTaintStep extends TaintTracking::AdditionalTaintStep { |
| 57 | + override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { |
| 58 | + // Methods |
| 59 | + // |
| 60 | + // TODO: When we have tools that make it easy, model these properly to handle |
| 61 | + // `meth = obj.meth; meth()`. Until then, we'll use this more syntactic approach |
| 62 | + // (since it allows us to at least capture the most common cases). |
| 63 | + nodeFrom = instance() and |
| 64 | + exists(DataFlow::AttrRead attr | attr.getObject() = nodeFrom | |
| 65 | + // methods (non-async) |
| 66 | + attr.getAttributeName() in ["getone", "getall"] and |
| 67 | + nodeTo.(DataFlow::CallCfgNode).getFunction() = attr |
| 68 | + ) |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments