Add support for per-file rule ignores in configuration

Open
#1,322 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Quiet
Tech stack
python
Domain
security, tooling

Research direction

Start by tracing Bandit's existing global-ignore configuration and inline #nosec handling. Define how configuration-based file and rule matching should work, then verify that exclusions apply only to the named files while unrelated findings remain enabled.

Written by the indexing model from the issue text.

Description

enhancement

Is your feature request related to a problem? Please describe.
I'm often frustrated when I need to skip specific Bandit checks for certain files, such as test files that intentionally use pseudo-randomization (e.g. random). Currently, Bandit only supports global ignores or inline #nosec comments.
Inline #nosec comments lead to many extra lines and make the code visually cluttered, especially in large test suites. Global ignores, on the other hand, suppress valid issues in unrelated files.
There’s no clean way to configure per-file rule exclusions directly in the configuration file.

Describe the solution you'd like
I would like Bandit to support per-file ignores directly in the configuration file.

Describe alternatives you've considered
Using inline #nosec comments - creates clutter and reduces code readability.
Ignoring rules globally - too broad and hides potential issues in other files.
Neither solution provides the desired control.

Additional context

Love this idea? Give it a 👍. We prioritize fulfilling features with the most 👍.

Dominant language
Python
Stars
8.4k
Forks
893
Avg merge
6h 52m
Merged PRs (30d)
3

Getting set up

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.

More from PyCQA/bandit

All issues in PyCQA/bandit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.