Skip to content

Commit 5e2c818

Browse files
authored
[flake8-bandit] Mark tuples of string literals as trusted input in S603 (astral-sh#17801)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Fixes astral-sh#17798 <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan Snapshot tests <!-- How was it tested? -->
1 parent 90c12f4 commit 5e2c818

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_bandit/S603.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@
3939
# But non-instant are not.
4040
(e := "echo")
4141
run(e)
42+
43+
44+
# https://github.com/astral-sh/ruff/issues/17798
45+
# Tuple literals are trusted
46+
check_output(("literal", "cmd", "using", "tuple"), text=True)
47+
Popen(("literal", "cmd", "using", "tuple"))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,11 @@ impl Violation for UnixCommandWildcardInjection {
289289
}
290290

291291
/// Check if an expression is a trusted input for subprocess.run.
292-
/// We assume that any str or list[str] literal can be trusted.
292+
/// We assume that any str, list[str] or tuple[str] literal can be trusted.
293293
fn is_trusted_input(arg: &Expr) -> bool {
294294
match arg {
295295
Expr::StringLiteral(_) => true,
296-
Expr::List(ast::ExprList { elts, .. }) => {
296+
Expr::List(ast::ExprList { elts, .. }) | Expr::Tuple(ast::ExprTuple { elts, .. }) => {
297297
elts.iter().all(|elt| matches!(elt, Expr::StringLiteral(_)))
298298
}
299299
Expr::Named(named) => is_trusted_input(&named.value),

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,20 @@ S603.py:41:1: S603 `subprocess` call: check for execution of untrusted input
200200
41 | run(e)
201201
| ^^^ S603
202202
|
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+
|

0 commit comments

Comments
 (0)