Skip to content

Conversation

@mkniewallner
Copy link

Version 1.7.3 of Python SAST tool bandit added support for disabling individual tests in PyCQA/bandit#597.

It is now possible to disable specific codes like so:

# nosec: B101, B102
# nosec: B101 subprocess_popen_with_shell_equals_true

I thought that this could be a nice thing to have in this project.

@mkniewallner mkniewallner marked this pull request as ready for review March 1, 2022 21:11
- id: python-check-blanket-nosec
name: check blanket nosec
description: 'Enforce that bandit `nosec` annotations always occur with specific codes. Sample annotations: `# nosec: B101`, `# nosec: B101,B102`'
entry: '# *nosec(?!: *\w)'
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason this is different from the noqa pattern?

Copy link
Author

@mkniewallner mkniewallner Mar 1, 2022

Choose a reason for hiding this comment

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

It is to have something similar to bandit regex (https://github.com/PyCQA/bandit/blob/5747e306262d71aca46542f71c6fda116de98b6c/bandit/core/manager.py#L25), though for consistency it may indeed be nice to have something closer to noqa pattern (maybe without (?i), as nosec is case sensitive).

@ericbuehl
Copy link

I just posted a nearly identical PR before seeing this one. 🤦 Here is the regex I came up with:

entry: '(?i)#\s*nosec:?\s*(?![^#])'

@ericbuehl ericbuehl mentioned this pull request Sep 20, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants