Skip to content

Commit 4108139

Browse files
author
Alvaro Muñoz
committed
Upgrade CommandInjection query to use the latest DF interface
1 parent ef0d3d6 commit 4108139

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

go/src/security/CWE-078/CommandInjection.ql

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@
1313

1414
import go
1515
import semmle.go.security.CommandInjection
16-
import DataFlow::PathGraph
17-
import semmle.go.security.FlowSources
16+
import semmle.go.security.CommandInjectionCustomizations::CommandInjection
1817

1918
//Override CommandInjection::Configuration to use the in-use sources
20-
class InUseCommandInjectionConfiguration extends CommandInjection::Configuration {
21-
override predicate isSource(DataFlow::Node node) {
19+
class InUseAsSource extends Source instanceof UntrustedFlowSource {
20+
InUseAsSource() {
2221
exists(UntrustedFlowSource source, Function function, DataFlow::CallNode callNode |
23-
source.asExpr() = node.asExpr() and
22+
source.asExpr() = this.asExpr() and
2423
source.(DataFlow::ExprNode).asExpr().getEnclosingFunction() = function.getFuncDecl() and
2524
(
2625
// function is called directly
@@ -33,9 +32,16 @@ class InUseCommandInjectionConfiguration extends CommandInjection::Configuration
3332
}
3433
}
3534

36-
from
37-
InUseCommandInjectionConfiguration cfg, CommandInjection::DoubleDashSanitizingConfiguration cfg2,
38-
DataFlow::PathNode source, DataFlow::PathNode sink
39-
where (cfg.hasFlowPath(source, sink) or cfg2.hasFlowPath(source, sink))
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())
4046
select sink.getNode(), source, sink, "This command depends on a $@.", source.getNode(),
4147
"user-provided value"

0 commit comments

Comments
 (0)