Skip to content

Commit 00e9de8

Browse files
dylwil3ntBre
authored andcommitted
[flake8-bandit] Stabilize more trusted inputs in subprocess-without-shell-equals-true (S603) (#18521)
1 parent 7211660 commit 00e9de8

File tree

5 files changed

+1
-231
lines changed

5 files changed

+1
-231
lines changed

crates/ruff_linter/src/preview.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ pub(crate) const fn is_full_path_match_source_strategy_enabled(settings: &Linter
1818

1919
// Rule-specific behavior
2020

21-
// https://github.com/astral-sh/ruff/pull/17136
22-
pub(crate) const fn is_shell_injection_only_trusted_input_enabled(
23-
settings: &LinterSettings,
24-
) -> bool {
25-
settings.preview.is_enabled()
26-
}
27-
2821
// https://github.com/astral-sh/ruff/pull/15541
2922
pub(crate) const fn is_suspicious_function_reference_enabled(settings: &LinterSettings) -> bool {
3023
settings.preview.is_enabled()

crates/ruff_linter/src/rules/flake8_bandit/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ mod tests {
104104
#[test_case(Rule::SuspiciousURLOpenUsage, Path::new("S310.py"))]
105105
#[test_case(Rule::SuspiciousNonCryptographicRandomUsage, Path::new("S311.py"))]
106106
#[test_case(Rule::SuspiciousTelnetUsage, Path::new("S312.py"))]
107-
#[test_case(Rule::SubprocessWithoutShellEqualsTrue, Path::new("S603.py"))]
108107
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
109108
let snapshot = format!(
110109
"preview__{}_{}",

crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use ruff_python_semantic::SemanticModel;
77
use ruff_text_size::Ranged;
88

99
use crate::Violation;
10-
use crate::preview::is_shell_injection_only_trusted_input_enabled;
1110
use crate::{
1211
checkers::ast::Checker, registry::Rule, rules::flake8_bandit::helpers::string_literal,
1312
};
@@ -325,9 +324,7 @@ pub(crate) fn shell_injection(checker: &Checker, call: &ast::ExprCall) {
325324
}
326325
// S603
327326
_ => {
328-
if !is_trusted_input(arg)
329-
|| !is_shell_injection_only_trusted_input_enabled(checker.settings)
330-
{
327+
if !is_trusted_input(arg) {
331328
if checker.enabled(Rule::SubprocessWithoutShellEqualsTrue) {
332329
checker.report_diagnostic(
333330
SubprocessWithoutShellEqualsTrue,

crates/ruff_linter/src/rules/flake8_bandit/snapshots/ruff_linter__rules__flake8_bandit__tests__S603_S603.py.snap

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -106,74 +106,6 @@ S603.py:21:1: S603 `subprocess` call: check for execution of untrusted input
106106
23 | # Literals are fine, they're trusted.
107107
|
108108

109-
S603.py:24:1: S603 `subprocess` call: check for execution of untrusted input
110-
|
111-
23 | # Literals are fine, they're trusted.
112-
24 | run("true")
113-
| ^^^ S603
114-
25 | Popen(["true"])
115-
26 | Popen("true", shell=False)
116-
|
117-
118-
S603.py:25:1: S603 `subprocess` call: check for execution of untrusted input
119-
|
120-
23 | # Literals are fine, they're trusted.
121-
24 | run("true")
122-
25 | Popen(["true"])
123-
| ^^^^^ S603
124-
26 | Popen("true", shell=False)
125-
27 | call("true", shell=False)
126-
|
127-
128-
S603.py:26:1: S603 `subprocess` call: check for execution of untrusted input
129-
|
130-
24 | run("true")
131-
25 | Popen(["true"])
132-
26 | Popen("true", shell=False)
133-
| ^^^^^ S603
134-
27 | call("true", shell=False)
135-
28 | check_call("true", shell=False)
136-
|
137-
138-
S603.py:27:1: S603 `subprocess` call: check for execution of untrusted input
139-
|
140-
25 | Popen(["true"])
141-
26 | Popen("true", shell=False)
142-
27 | call("true", shell=False)
143-
| ^^^^ S603
144-
28 | check_call("true", shell=False)
145-
29 | check_output("true", shell=False)
146-
|
147-
148-
S603.py:28:1: S603 `subprocess` call: check for execution of untrusted input
149-
|
150-
26 | Popen("true", shell=False)
151-
27 | call("true", shell=False)
152-
28 | check_call("true", shell=False)
153-
| ^^^^^^^^^^ S603
154-
29 | check_output("true", shell=False)
155-
30 | run("true", shell=False)
156-
|
157-
158-
S603.py:29:1: S603 `subprocess` call: check for execution of untrusted input
159-
|
160-
27 | call("true", shell=False)
161-
28 | check_call("true", shell=False)
162-
29 | check_output("true", shell=False)
163-
| ^^^^^^^^^^^^ S603
164-
30 | run("true", shell=False)
165-
|
166-
167-
S603.py:30:1: S603 `subprocess` call: check for execution of untrusted input
168-
|
169-
28 | check_call("true", shell=False)
170-
29 | check_output("true", shell=False)
171-
30 | run("true", shell=False)
172-
| ^^^ S603
173-
31 |
174-
32 | # Not through assignments though.
175-
|
176-
177109
S603.py:34:1: S603 `subprocess` call: check for execution of untrusted input
178110
|
179111
32 | # Not through assignments though.
@@ -184,36 +116,10 @@ S603.py:34:1: S603 `subprocess` call: check for execution of untrusted input
184116
36 | # Instant named expressions are fine.
185117
|
186118

187-
S603.py:37:1: S603 `subprocess` call: check for execution of untrusted input
188-
|
189-
36 | # Instant named expressions are fine.
190-
37 | run(c := "true")
191-
| ^^^ S603
192-
38 |
193-
39 | # But non-instant are not.
194-
|
195-
196119
S603.py:41:1: S603 `subprocess` call: check for execution of untrusted input
197120
|
198121
39 | # But non-instant are not.
199122
40 | (e := "echo")
200123
41 | run(e)
201124
| ^^^ S603
202125
|
203-
204-
S603.py:46:1: S603 `subprocess` call: check for execution of untrusted input
205-
|
206-
44 | # https://github.com/astral-sh/ruff/issues/17798
207-
45 | # Tuple literals are trusted
208-
46 | check_output(("literal", "cmd", "using", "tuple"), text=True)
209-
| ^^^^^^^^^^^^ S603
210-
47 | Popen(("literal", "cmd", "using", "tuple"))
211-
|
212-
213-
S603.py:47:1: S603 `subprocess` call: check for execution of untrusted input
214-
|
215-
45 | # Tuple literals are trusted
216-
46 | check_output(("literal", "cmd", "using", "tuple"), text=True)
217-
47 | Popen(("literal", "cmd", "using", "tuple"))
218-
| ^^^^^ S603
219-
|

crates/ruff_linter/src/rules/flake8_bandit/snapshots/ruff_linter__rules__flake8_bandit__tests__preview__S603_S603.py.snap

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)