Skip to content
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

False nosec encountered warning #1041

Open
costaparas opened this issue Aug 16, 2023 · 2 comments
Open

False nosec encountered warning #1041

costaparas opened this issue Aug 16, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@costaparas
Copy link
Contributor

costaparas commented Aug 16, 2023

Describe the bug

The warning text "WARNING nosec encountered (X), but no failed test on line Y" incorrectly appears in some cases. It may also appear more than once for the same line number and test under specific circumstances.

Reproduction steps

Consider this base code:

import shlex
import subprocess
proc = subprocess.Popen(args=shlex.split("ffmpeg -i file.mp3"))

Since there are 2 function calls on this line of code, there are 2 calls to run_tests in bandit/core/issue.py.

If we include a nosec comment specifying the correct test to ignore (i.e. B603):

import shlex
import subprocess
proc = subprocess.Popen(args=shlex.split("ffmpeg -i file.mp3"))  # nosec: B603

the following warning text displays:

WARNING	nosec encountered (B603), but no failed test on line 3

If we include a nosec comment specifying something else (e.g. B602):

import shlex
import subprocess
proc = subprocess.Popen(args=shlex.split("ffmpeg -i file.mp3"))  # nosec: B602

the following warning text displays:

WARNING	nosec encountered (B602), but no failed test on line 3
WARNING	nosec encountered (B602), but no failed test on line 3

Expected behavior

  • The warning text should not appear more than once for the same line number and test.
  • The warning should only appear if there is no failed test on the line for the specified test only.

Bandit version

1.7.5 (Default)

Python version

3.10

Additional context

No response

@costaparas costaparas added the bug Something isn't working label Aug 16, 2023
@drammock
Copy link

possible duplicate of #942 ?

@costaparas
Copy link
Contributor Author

possible duplicate of #942 ?

Partially, yes. But #942 does not explicitly mention the case where you may get duplicate warning text. They are closely related issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants