PyCQA / PyCQA/bandit

New `exclude_regex` Filter to Address False Positives on Password Tests

Open
#973 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

  • exclude and exclude_dirs skips entire files/folders and are too permissive
  • skips completely skips entire tests and are too permissive
  • # nosec entries 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.