|
13 | 13 |
|
14 | 14 | import go |
15 | 15 | import semmle.go.security.CommandInjection |
16 | | -import semmle.go.security.CommandInjectionCustomizations::CommandInjection |
| 16 | +import DataFlow::PathGraph |
| 17 | +import semmle.go.security.FlowSources |
17 | 18 |
|
18 | 19 | //Override CommandInjection::Configuration to use the in-use sources |
19 | | -class InUseAsSource extends Source instanceof UntrustedFlowSource { |
20 | | - InUseAsSource() { |
| 20 | +class InUseCommandInjectionConfiguration extends CommandInjection::Configuration { |
| 21 | + override predicate isSource(DataFlow::Node node) { |
21 | 22 | exists(UntrustedFlowSource source, Function function, DataFlow::CallNode callNode | |
22 | | - source.asExpr() = this.asExpr() and |
| 23 | + source.asExpr() = node.asExpr() and |
| 24 | + |
23 | 25 | source.(DataFlow::ExprNode).asExpr().getEnclosingFunction() = function.getFuncDecl() and |
24 | 26 | ( |
25 | 27 | // function is called directly |
26 | 28 | callNode.getACallee() = function.getFuncDecl() |
27 | | - or |
| 29 | + |
28 | 30 | // function is passed to another function to be called |
29 | | - callNode.getCall().getAnArgument().(Ident).refersTo(function) //NEW with 2.13.2: or c.getASyntacticArgument().asExpr().(Ident).refersTo(f) |
30 | | - ) |
| 31 | + or callNode.getCall().getAnArgument().(Ident).refersTo(function) //NEW with 2.13.2: or c.getASyntacticArgument().asExpr().(Ident).refersTo(f) |
| 32 | + ) |
31 | 33 | ) |
32 | 34 | } |
33 | 35 | } |
34 | 36 |
|
35 | | -module Flow = |
36 | | - DataFlow::MergePathGraph<CommandInjection::Flow::PathNode, |
37 | | - CommandInjection::DoubleDashSanitizingFlow::PathNode, CommandInjection::Flow::PathGraph, |
38 | | - CommandInjection::DoubleDashSanitizingFlow::PathGraph>; |
39 | | - |
40 | | -import Flow::PathGraph |
41 | | - |
42 | | -from Flow::PathNode source, Flow::PathNode sink |
43 | | -where |
44 | | - CommandInjection::Flow::flowPath(source.asPathNode1(), sink.asPathNode1()) or |
45 | | - CommandInjection::DoubleDashSanitizingFlow::flowPath(source.asPathNode2(), sink.asPathNode2()) |
46 | | -select sink.getNode(), source, sink, "This command depends on a $@.", source.getNode(), |
47 | | - "user-provided value" |
| 37 | + from InUseCommandInjectionConfiguration cfg, CommandInjection::DoubleDashSanitizingConfiguration cfg2, DataFlow::PathNode source, DataFlow::PathNode sink |
| 38 | + where (cfg.hasFlowPath(source, sink) or cfg2.hasFlowPath(source, sink)) |
| 39 | + select sink.getNode(), source, sink, "This command depends on a $@.", source.getNode(), "user-provided value" |
0 commit comments