Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions go/src/security/CWE-078/CommandInjection.ql
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,27 @@

import go
import semmle.go.security.CommandInjection
import semmle.go.security.CommandInjectionCustomizations::CommandInjection
import DataFlow::PathGraph
import semmle.go.security.FlowSources

//Override CommandInjection::Configuration to use the in-use sources
class InUseAsSource extends Source instanceof UntrustedFlowSource {
InUseAsSource() {
class InUseCommandInjectionConfiguration extends CommandInjection::Configuration {
override predicate isSource(DataFlow::Node node) {
exists(UntrustedFlowSource source, Function function, DataFlow::CallNode callNode |
source.asExpr() = this.asExpr() and
source.asExpr() = node.asExpr() and

source.(DataFlow::ExprNode).asExpr().getEnclosingFunction() = function.getFuncDecl() and
(
// function is called directly
callNode.getACallee() = function.getFuncDecl()
or

// function is passed to another function to be called
callNode.getCall().getAnArgument().(Ident).refersTo(function) //NEW with 2.13.2: or c.getASyntacticArgument().asExpr().(Ident).refersTo(f)
)
or callNode.getCall().getAnArgument().(Ident).refersTo(function) //NEW with 2.13.2: or c.getASyntacticArgument().asExpr().(Ident).refersTo(f)
)
)
}
}

module Flow =
DataFlow::MergePathGraph<CommandInjection::Flow::PathNode,
CommandInjection::DoubleDashSanitizingFlow::PathNode, CommandInjection::Flow::PathGraph,
CommandInjection::DoubleDashSanitizingFlow::PathGraph>;

import Flow::PathGraph

from Flow::PathNode source, Flow::PathNode sink
where
CommandInjection::Flow::flowPath(source.asPathNode1(), sink.asPathNode1()) or
CommandInjection::DoubleDashSanitizingFlow::flowPath(source.asPathNode2(), sink.asPathNode2())
select sink.getNode(), source, sink, "This command depends on a $@.", source.getNode(),
"user-provided value"
from InUseCommandInjectionConfiguration cfg, CommandInjection::DoubleDashSanitizingConfiguration cfg2, DataFlow::PathNode source, DataFlow::PathNode sink
where (cfg.hasFlowPath(source, sink) or cfg2.hasFlowPath(source, sink))
select sink.getNode(), source, sink, "This command depends on a $@.", source.getNode(), "user-provided value"