ruff: Potential conflicted rules between S602 and S603
After bumping ruff from 0.0.261 to 0.0.262, I’m getting conflicted errors from the rules S602 and S603. See below for the minimal code snippet:
from subprocess import PIPE, Popen
proc = Popen(["/foo/bar"], stdout=PIPE, stderr=PIPE, shell=False)
I have been setting shell=False as per the S602 rule. However, running this snippet with ruff 0.0.262 errors with the S603 rule, which suggests to set shell=True. And if I do that, then the code is failing the S602 rule. Would you be able to check and see if this is intentional?
You can find the GitHub Action logs here with the above error introduced in 0.0.262.
And you can find my ruff config here.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 16 (10 by maintainers)
Commits related to this issue
- Ignore Ruff S603 It's causing a lot of false positives, complaining about perfectly safe usages of the subprocess module. See also https://github.com/astral-sh/ruff/issues/4045. — committed to Tony7466/Tails by segfault3 3 years ago
- Ignore ruff S603 It's a silly false-positive, see https://github.com/astral-sh/ruff/issues/4045 — committed to stefanor/hatch-mypyc by stefanor 2 years ago
- Ignore ruff S603 It's a silly false-positive, see https://github.com/astral-sh/ruff/issues/4045 — committed to stefanor/hatch-mypyc by stefanor 2 years ago
- Ignore ruff S603 It's a silly false-positive, see https://github.com/astral-sh/ruff/issues/4045 — committed to stefanor/hatch-mypyc by stefanor 2 years ago
- Ignore ruff S603 It's a silly false-positive, see https://github.com/astral-sh/ruff/issues/4045 — committed to stefanor/hatch-mypyc by stefanor 2 years ago
Huh, interesting. So I guess we’re consistent with Bandit here? And the only workaround within Bandit is to add a
# nosecor similar, to allow low-risksubprocesscalls?I suppose we could consider removing
S603altogether. Or, we could modifyS603to only flag calls with dynamic arguments, like variables, and let all-string calls be considered “safe”, which seems to be what they suggest in that issue.Yes, this rule (S602) seems completely useless right now. It triggers on a simple
subprocess.check_output(['/usr/bin/foo'])which has zero non-hardcoded input…I think that
S603makes sense if (even one of) the arguments are dynamic, but for static arguments, it doesn’t offer muchAny plans for this?
I vote for removal or opt-in since even non-literal statics trigger:
I think this Issue on bandit might be related to the behaviour we’re seeing here with ruff? https://github.com/PyCQA/bandit/issues/333
I’m confused between these two as they’re the exact opposite of each other. If we try to make them mutually exclusive, then which one to detect first?
I think we should actually look into why these two rules exists in the first place and then decide what the fix should be.
Relevant docs:
(A bit late here so calling it a day 😃)
They’re here 😃
https://github.com/charliermarsh/ruff/blob/cb762f4cad62000e8cd5fa26fec35b228e3bc5d8/crates/ruff/src/rules/flake8_bandit/rules/shell_injection.rs#L252-L253