Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 700841e

Browse files
committed
Python: Move UnsafeShellCommandConstruction to new dataflow API
1 parent d4e4e2d commit 700841e

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

python/ql/lib/semmle/python/security/dataflow/UnsafeShellCommandConstructionQuery.qll

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ private import CommandInjectionCustomizations::CommandInjection as CommandInject
1414
private import semmle.python.dataflow.new.BarrierGuards
1515

1616
/**
17+
* DEPRECATED: Use `UnsafeShellCommandConstructionFlow` module instead.
18+
*
1719
* A taint-tracking configuration for detecting shell command constructed from library input vulnerabilities.
1820
*/
19-
class Configuration extends TaintTracking::Configuration {
21+
deprecated class Configuration extends TaintTracking::Configuration {
2022
Configuration() { this = "UnsafeShellCommandConstruction" }
2123

2224
override predicate isSource(DataFlow::Node source) { source instanceof Source }
@@ -32,3 +34,20 @@ class Configuration extends TaintTracking::Configuration {
3234
result instanceof DataFlow::FeatureHasSourceCallContext
3335
}
3436
}
37+
38+
private module UnsafeShellCommandConstructionConfig implements DataFlow::ConfigSig {
39+
predicate isSource(DataFlow::Node source) { source instanceof Source }
40+
41+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
42+
43+
predicate isBarrier(DataFlow::Node node) {
44+
node instanceof CommandInjection::Sanitizer // using all sanitizers from `py/command-injection`
45+
}
46+
47+
// override to require the path doesn't have unmatched return steps
48+
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
49+
}
50+
51+
/** Global taint-tracking for detecting "shell command constructed from library input" vulnerabilities. */
52+
module UnsafeShellCommandConstructionFlow =
53+
TaintTracking::Global<UnsafeShellCommandConstructionConfig>;

python/ql/src/Security/CWE-078/UnsafeShellCommandConstruction.ql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
import python
1818
import semmle.python.security.dataflow.UnsafeShellCommandConstructionQuery
19-
import DataFlow::PathGraph
19+
import UnsafeShellCommandConstructionFlow::PathGraph
2020

21-
from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink, Sink sinkNode
21+
from
22+
UnsafeShellCommandConstructionFlow::PathNode source,
23+
UnsafeShellCommandConstructionFlow::PathNode sink, Sink sinkNode
2224
where
23-
config.hasFlowPath(source, sink) and
25+
UnsafeShellCommandConstructionFlow::flowPath(source, sink) and
2426
sinkNode = sink.getNode()
2527
select sinkNode.getStringConstruction(), source, sink,
2628
"This " + sinkNode.describe() + " which depends on $@ is later used in a $@.", source.getNode(),

0 commit comments

Comments
 (0)