|
| 1 | + |
| 2 | +/** |
| 3 | + * @id codeql-zero-to-hero/4-7 |
| 4 | + * @severity error |
| 5 | + * @kind path-problem |
| 6 | + */ |
| 7 | + |
| 8 | + |
| 9 | + import python |
| 10 | + import semmle.python.dataflow.new.DataFlow |
| 11 | + import semmle.python.dataflow.new.TaintTracking |
| 12 | + import semmle.python.ApiGraphs |
| 13 | + import semmle.python.dataflow.new.RemoteFlowSources |
| 14 | + import MyFlow::PathGraph |
| 15 | + |
| 16 | +class GradioButton extends RemoteFlowSource::Range { |
| 17 | + GradioButton() { |
| 18 | + exists(API::CallNode n | |
| 19 | + n = API::moduleImport("gradio").getMember("Button").getReturn() |
| 20 | + .getMember("click").getACall() | |
| 21 | + this = n.getParameter(0, "fn").getParameter(_).asSource()) |
| 22 | + } |
| 23 | + |
| 24 | + override string getSourceType() { result = "Gradio untrusted input" } |
| 25 | + |
| 26 | + } |
| 27 | + |
| 28 | + class GradioInterface extends RemoteFlowSource::Range { |
| 29 | + GradioInterface() { |
| 30 | + exists(API::CallNode n | |
| 31 | + n = API::moduleImport("gradio").getMember("Interface").getACall() | |
| 32 | + this = n.getParameter(0, "fn").getParameter(_).asSource()) |
| 33 | + } |
| 34 | + override string getSourceType() { result = "Gradio untrusted input" } |
| 35 | + |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +class OsSystemSink extends API::CallNode { |
| 41 | + OsSystemSink() { |
| 42 | + this = API::moduleImport("os").getMember("system").getACall() |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | + private module MyConfig implements DataFlow::ConfigSig { |
| 47 | + predicate isSource(DataFlow::Node source) { |
| 48 | + source instanceof RemoteFlowSource |
| 49 | + } |
| 50 | + |
| 51 | + predicate isSink(DataFlow::Node sink) { |
| 52 | + exists(OsSystemSink call | |
| 53 | + sink = call.getArg(0) |
| 54 | + ) |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + module MyFlow = TaintTracking::Global<MyConfig>; |
| 59 | + |
| 60 | + from MyFlow::PathNode source, MyFlow::PathNode sink |
| 61 | + where MyFlow::flowPath(source, sink) |
| 62 | + select sink.getNode(), source, sink, "Data Flow from a Gradio source to `os.system`" |
0 commit comments