Skip to content

[flake8-bandit] Mark tuples of string literals as trusted input in S603 #17801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025

Conversation

LaBatata101
Copy link
Contributor

Summary

Fixes #17798

Test Plan

Snapshot tests

Copy link
Contributor

github-actions bot commented May 2, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -1 violations, +0 -0 fixes in 1 projects; 54 projects unchanged)

bokeh/bokeh (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- setup.py:127:20: S603 `subprocess` call: check for execution of untrusted input

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
S603 1 0 1 0 0

@LaBatata101 LaBatata101 marked this pull request as ready for review May 2, 2025 22:36
@Avasam
Copy link
Contributor

Avasam commented May 5, 2025

Might be a nitpick, but technically the python type is tuple[str, ...] (tuple[str] is a single item tuple)

@ntBre ntBre added the rule Implementing or modifying a lint rule label May 5, 2025
Comment on lines +206 to +218
44 | # https://github.com/astral-sh/ruff/issues/17798
45 | # Tuple literals are trusted
46 | check_output(("literal", "cmd", "using", "tuple"), text=True)
| ^^^^^^^^^^^^ S603
47 | Popen(("literal", "cmd", "using", "tuple"))
|

S603.py:47:1: S603 `subprocess` call: check for execution of untrusted input
|
45 | # Tuple literals are trusted
46 | check_output(("literal", "cmd", "using", "tuple"), text=True)
47 | Popen(("literal", "cmd", "using", "tuple"))
| ^^^^^ S603
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these both showing that tuples are still flagged? I thought we should expect not to see a diagnostic here now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot, I forgot to comment about that. So, if I run using the check command in this code, no diagnostics are flagged.

from subprocess import Popen, check_output

check_output(("literal", "cmd", "using", "tuple"), text=True)
Popen(("literal", "cmd", "using", "tuple"))
$ cargo run -p ruff -- check sample.py --preview --no-cache --select S603
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s
    Running `target/debug/ruff check sample2.py --preview --no-cache --select S603`
All checks passed!

I don't know why it's only creating the diagnostics for the snapshot test. Do you have any idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh, I see. The same Python file (S603.py) is passed to both the rules test and the preview_rules case. We're not seeing a snapshot for the preview version because your change is working properly! This snapshot is for the non-preview version, which correctly shows the diagnostic, my mistake.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I'll update the title to say tuples of string literals in line with @Avasam's suggestion, but I think the inline tuple[str] comment is fine :)

@ntBre ntBre changed the title [flake8-bandit] Mark tuple[str] literal as trusted input in S603 [flake8-bandit] Mark tuples of string literals as trusted input in S603 May 5, 2025
@ntBre ntBre added the preview Related to preview mode features label May 5, 2025
@ntBre ntBre merged commit 5e2c818 into astral-sh:main May 5, 2025
34 checks passed
@LaBatata101 LaBatata101 deleted the fix-S603 branch May 5, 2025 14:51
AlexWaygood pushed a commit that referenced this pull request May 5, 2025
…`S603` (#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 #17798
<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

Snapshot tests
<!-- How was it tested? -->
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request May 6, 2025
…`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? -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

subprocess-without-shell-equals-true (S603) false-positives on tuples
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy