Skip to content

Update CommandInjection.ql #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2023
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"