Skip to content

Commit 7598549

Browse files
committed
fix various nits based on feedback
1 parent 8e05fdb commit 7598549

File tree

6 files changed

+10
-11
lines changed

6 files changed

+10
-11
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ module UnsafeShellCommandConstruction {
6868
Fstring fstring;
6969

7070
StringInterpolationAsSink() {
71-
isUsedAsShellCommand(any(DataFlow::Node n | n.asExpr() = fstring), s) and
71+
isUsedAsShellCommand(DataFlow::exprNode(fstring), s) and
7272
this.asExpr() = fstring.getASubExpression()
7373
}
7474

75-
override string describe() { result = "string construction" }
75+
override string describe() { result = "f-string" }
7676

7777
override DataFlow::Node getCommandExecution() { result = s }
7878

@@ -101,7 +101,7 @@ module UnsafeShellCommandConstruction {
101101
}
102102

103103
/**
104-
* A string constructed using a `.join(" ")` call, where the resulting string ends up being executed as a shell command.
104+
* A string constructed using a `" ".join(...)` call, where the resulting string ends up being executed as a shell command.
105105
*/
106106
class ArrayJoin extends Sink {
107107
Concepts::SystemCommandExecution s;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class Configuration extends TaintTracking::Configuration {
2424
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
2525

2626
override predicate isSanitizer(DataFlow::Node node) {
27-
node instanceof CommandInjection::Sanitizer or // using all sanitizers from `rb/command-injection`
28-
node instanceof StringConstCompareBarrier
27+
node instanceof CommandInjection::Sanitizer // using all sanitizers from `rb/command-injection`
2928
}
3029

3130
// override to require the path doesn't have unmatched return steps

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<qhelp>
55
<overview>
66
<p>
7-
Dynamically constructing a shell command with inputs from exported
7+
Dynamically constructing a shell command with inputs from library
88
functions may inadvertently change the meaning of the shell command.
99

1010
Clients using the exported function may use inputs containing
@@ -21,7 +21,7 @@
2121

2222
<p>
2323
If possible, provide the dynamic arguments to the shell as an array
24-
to APIs such as <code>system(..)</code> to avoid interpretation by the shell.
24+
to APIs such as <code>subprocess.run</code> to avoid interpretation by the shell.
2525
</p>
2626

2727
<p>
@@ -55,7 +55,7 @@
5555

5656
<p>
5757
To avoid such potentially catastrophic behaviors, provide the
58-
input from exported functions as an argument that does not
58+
input from library functions as an argument that does not
5959
get interpreted by a shell:
6060
</p>
6161

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import os
22

3-
def download (path):
3+
def download(path):
44
os.system("wget " + path) # NOT OK
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import subprocess
22

3-
def download (path):
3+
def download(path):
44
subprocess.run(["wget", path]) # OK

python/ql/test/query-tests/Security/CWE-078-UnsafeShellCommandConstruction/UnsafeShellCommandConstruction.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ nodes
3030
subpaths
3131
#select
3232
| src/unsafe_shell_test.py:5:15:5:28 | ControlFlowNode for BinaryExpr | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | src/unsafe_shell_test.py:5:25:5:28 | ControlFlowNode for name | This string concatenation which depends on $@ is later used in a $@. | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | library input | src/unsafe_shell_test.py:5:5:5:29 | ControlFlowNode for Attribute() | shell command |
33-
| src/unsafe_shell_test.py:8:15:8:28 | ControlFlowNode for Fstring | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | src/unsafe_shell_test.py:8:23:8:26 | ControlFlowNode for name | This string construction which depends on $@ is later used in a $@. | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | library input | src/unsafe_shell_test.py:8:5:8:29 | ControlFlowNode for Attribute() | shell command |
33+
| src/unsafe_shell_test.py:8:15:8:28 | ControlFlowNode for Fstring | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | src/unsafe_shell_test.py:8:23:8:26 | ControlFlowNode for name | This f-string which depends on $@ is later used in a $@. | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | library input | src/unsafe_shell_test.py:8:5:8:29 | ControlFlowNode for Attribute() | shell command |
3434
| src/unsafe_shell_test.py:11:15:11:38 | ControlFlowNode for BinaryExpr | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | src/unsafe_shell_test.py:11:25:11:38 | ControlFlowNode for Attribute() | This string concatenation which depends on $@ is later used in a $@. | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | library input | src/unsafe_shell_test.py:11:5:11:39 | ControlFlowNode for Attribute() | shell command |
3535
| src/unsafe_shell_test.py:14:15:14:40 | ControlFlowNode for BinaryExpr | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | src/unsafe_shell_test.py:14:25:14:40 | ControlFlowNode for Attribute() | This string concatenation which depends on $@ is later used in a $@. | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | library input | src/unsafe_shell_test.py:14:5:14:41 | ControlFlowNode for Attribute() | shell command |
3636
| src/unsafe_shell_test.py:17:15:17:36 | ControlFlowNode for Attribute() | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | src/unsafe_shell_test.py:17:32:17:35 | ControlFlowNode for name | This formatted string which depends on $@ is later used in a $@. | src/unsafe_shell_test.py:4:22:4:25 | ControlFlowNode for name | library input | src/unsafe_shell_test.py:17:5:17:37 | ControlFlowNode for Attribute() | shell command |

0 commit comments

Comments
 (0)