New `exclude_regex` Filter to Address False Positives on Password Tests
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.3k
- Forks
- 835
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 1
Description
Is your feature request related to a problem? Please describe.
Consistent issues arise on false positives of "token"-matched variable names in tests B105 and B106.
See: https://github.com/PyCQA/bandit/issues/498, https://github.com/PyCQA/bandit/issues/842, https://github.com/PyCQA/bandit/issues/843, https://github.com/PyCQA/bandit/issues/211
Describe the solution you'd like
It would be useful to have an exclude_regex field available to filter variable names, and not just excludes at the files and tests level.
Describe alternatives you've considered
excludeandexclude_dirsskips entire files/folders and are too permissiveskipscompletely skips entire tests and are too permissive# nosecentries clutter source code when there are excessive false positives
Additional context
Ideally, coupling an exclude_regex with exclude would be ideal granularity.
Example pyproject.toml to exclude "token" variable name filtering only in files under "tests/" folders for B106:
[tool.bandit.hardcoded_password_funcarg]
exclude_dirs = ["tests"]
exclude_regex = ["token"]
👍?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how exclude and exclude_dirs are handled for the B105 and B106 password checks, then inspect their existing tests and configuration handling. Add coverage for exclude_regex matching variable names while retaining file and test-level filtering, and verify the documented pyproject.toml example behaves as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- security, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100