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

Most upvoted comments

Huh, interesting. So I guess we’re consistent with Bandit here? And the only workaround within Bandit is to add a # nosec or similar, to allow low-risk subprocess calls?

I suppose we could consider removing S603 altogether. Or, we could modify S603 to 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 S603 makes sense if (even one of) the arguments are dynamic, but for static arguments, it doesn’t offer much

Any plans for this?

I vote for removal or opt-in since even non-literal statics trigger:

[sys.executable, '-m', 'ruff', 'rule', '--all']

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 😃)