Skip to content

Commit d475bb9

Browse files
committed
Python: Add abstract class CommandSink
I'm going to add more in a sec, and listing *all* of them in CommandInjection.ql started to be silly
1 parent 9eee16b commit d475bb9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class CommandInjectionConfiguration extends TaintTracking::Configuration {
2929
}
3030

3131
override predicate isSink(TaintTracking::Sink sink) {
32-
sink instanceof OsCommandFirstArgument or
33-
sink instanceof ShellCommand
32+
sink instanceof CommandSink
3433
}
3534

3635
override predicate isExtension(TaintTracking::Extension extension) {

python/ql/src/semmle/python/security/injection/Command.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import python
1010
import semmle.python.security.TaintTracking
1111
import semmle.python.security.strings.Untrusted
1212

13+
/** Abstract taint sink that is potentially vulnerable to malicious shell commands. */
14+
abstract class CommandSink extends TaintSink { }
1315

1416
private ModuleObject osOrPopenModule() {
1517
result.getName() = "os" or
@@ -20,7 +22,7 @@ private Object makeOsCall() {
2022
exists(string name |
2123
result = ModuleObject::named("subprocess").attr(name) |
2224
name = "Popen" or
23-
name = "call" or
25+
name = "call" or
2426
name = "check_call" or
2527
name = "check_output" or
2628
name = "run"
@@ -61,7 +63,7 @@ class FirstElementFlow extends DataFlowExtension::DataFlowNode {
6163
/** A taint sink that is potentially vulnerable to malicious shell commands.
6264
* The `vuln` in `subprocess.call(shell=vuln)` and similar calls.
6365
*/
64-
class ShellCommand extends TaintSink {
66+
class ShellCommand extends CommandSink {
6567

6668
override string toString() { result = "shell command" }
6769

@@ -100,7 +102,7 @@ class ShellCommand extends TaintSink {
100102
/** A taint sink that is potentially vulnerable to malicious shell commands.
101103
* The `vuln` in `subprocess.call(vuln, ...)` and similar calls.
102104
*/
103-
class OsCommandFirstArgument extends TaintSink {
105+
class OsCommandFirstArgument extends CommandSink {
104106

105107
override string toString() { result = "OS command first argument" }
106108

0 commit comments

Comments
 (0)