|
| 1 | +/** |
| 2 | + * @name Gradio Button partial path graph |
| 3 | + * @description This query tracks data flow from Gradio's Button component to any sink. |
| 4 | + * @kind path-problem |
| 5 | + * @problem.severity warning |
| 6 | + * @id 5/4 |
| 7 | + */ |
| 8 | + |
| 9 | +import python |
| 10 | +import semmle.python.ApiGraphs |
| 11 | +import semmle.python.Concepts |
| 12 | +import semmle.python.dataflow.new.RemoteFlowSources |
| 13 | +import semmle.python.dataflow.new.TaintTracking |
| 14 | + |
| 15 | +// import MyFlow::PathGraph |
| 16 | +import PartialFlow::PartialPathGraph |
| 17 | + |
| 18 | +class GradioButton extends RemoteFlowSource::Range { |
| 19 | + GradioButton() { |
| 20 | + exists(API::CallNode n | |
| 21 | + n = API::moduleImport("gradio").getMember("Button").getReturn() |
| 22 | + .getMember("click").getACall() | |
| 23 | + this = n.getParameter(0, "fn").getParameter(_).asSource()) |
| 24 | + } |
| 25 | + |
| 26 | + override string getSourceType() { result = "Gradio untrusted input" } |
| 27 | +} |
| 28 | + |
| 29 | +predicate nameAttrRead(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { |
| 30 | + // Connects an attribute read of an object's `name` attribute to the object itself |
| 31 | + exists(DataFlow::AttrRead attr | |
| 32 | + attr.accesses(nodeFrom, "name") |
| 33 | + and nodeTo = attr |
| 34 | + ) |
| 35 | +} |
| 36 | + |
| 37 | +private module MyConfig implements DataFlow::ConfigSig { |
| 38 | + predicate isSource(DataFlow::Node source) { source instanceof GradioButton } |
| 39 | + |
| 40 | + predicate isSink(DataFlow::Node sink) { exists(Decoding d | d.mayExecuteInput() | sink = d.getAnInput()) } |
| 41 | + |
| 42 | + predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { |
| 43 | + nameAttrRead(nodeFrom, nodeTo) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +module MyFlow = TaintTracking::Global<MyConfig>; |
| 49 | +int explorationLimit() { result = 10 } |
| 50 | +module PartialFlow = MyFlow::FlowExplorationFwd<explorationLimit/0>; |
| 51 | + |
| 52 | +from PartialFlow::PartialPathNode source, PartialFlow::PartialPathNode sink |
| 53 | +where PartialFlow::partialFlow(source, sink, _) |
| 54 | +select sink.getNode(), source, sink, "Partial Graph $@.", source.getNode(), "user-provided value." |
0 commit comments