|
| 1 | +/** |
| 2 | + * @name Command built from user-controlled sources |
| 3 | + * @description Building a system command from user-controlled sources is vulnerable to insertion of |
| 4 | + * malicious code by the user. |
| 5 | + * @kind path-problem |
| 6 | + * @problem.severity error |
| 7 | + * @security-severity 9 |
| 8 | + * @precision high |
| 9 | + * @id actions/command-injection |
| 10 | + * @tags actions |
| 11 | + * security |
| 12 | + * external/cwe/cwe-078 |
| 13 | + */ |
| 14 | + |
| 15 | +import actions |
| 16 | +import codeql.actions.TaintTracking |
| 17 | +import codeql.actions.dataflow.FlowSources |
| 18 | +import codeql.actions.dataflow.ExternalFlow |
| 19 | + |
| 20 | +private class CommandInjectionSink extends DataFlow::Node { |
| 21 | + CommandInjectionSink() { externallyDefinedSink(this, "command-injection") } |
| 22 | +} |
| 23 | + |
| 24 | +private module MyConfig implements DataFlow::ConfigSig { |
| 25 | + predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } |
| 26 | + |
| 27 | + predicate isSink(DataFlow::Node sink) { sink instanceof CommandInjectionSink } |
| 28 | +} |
| 29 | + |
| 30 | +module MyFlow = TaintTracking::Global<MyConfig>; |
| 31 | + |
| 32 | +import MyFlow::PathGraph |
| 33 | + |
| 34 | +from MyFlow::PathNode source, MyFlow::PathNode sink, Workflow w |
| 35 | +where |
| 36 | + MyFlow::flowPath(source, sink) and |
| 37 | + w = source.getNode().asExpr().getEnclosingWorkflow() and |
| 38 | + ( |
| 39 | + w instanceof ReusableWorkflow or |
| 40 | + w.hasTriggerEvent(source.getNode().(RemoteFlowSource).getATriggerEvent()) |
| 41 | + ) |
| 42 | +select sink.getNode(), source, sink, |
| 43 | + "Potential expression injection in $@, which may be controlled by an external user.", sink, |
| 44 | + sink.getNode().asExpr().(Expression).getRawExpression() |
0 commit comments