PyCQA / PyCQA/bandit

Exclusion filter not working correctly with relative paths

Open
#975 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
8.3k
Forks
835
Avg merge
5d 3h
Merged PRs (30d)
1

Description

Describe the bug

An exclusion filter like -x ./.tox seems to work as desired, but -x .tox doesn't exclude the same directory. I couldn't find any docs on what the exact syntax of exclusion filters should be, so I'd assume both are supported.

Reproduction steps
  1. Have a large .tox folder at the root level of a project

  2. Run bandit -x ./.tox -ll -f json -o bandit.json -r . and observe that 94 (or some other small number) of things will be scanned

% bandit -x ./.tox -ll -f json -o bandit.json -r .
[main]	INFO	profile include tests: None
[main]	INFO	profile exclude tests: None
[main]	INFO	cli include tests: None
[main]	INFO	cli exclude tests: None
94 [0.. 50.. ]
[json]	INFO	JSON output written to file: bandit.json
  1. Run bandit -x .tox -ll -f json -o bandit.json -r . and observe that 19282 (or some other large number) of things will be scanned
% bandit -x .tox -ll -f json -o bandit.json -r . 
[main]	INFO	profile include tests: None
[main]	INFO	profile exclude tests: None
[main]	INFO	cli include tests: None
[main]	INFO	cli exclude tests: None
19282 [0.. 50.. ^C
Expected behavior

The two exclusion filters should be equivalent.

Bandit version

1.7.4 (Default)

Python version

3.9

Additional context

The danger of this bug is that files/directories might be unintentionally included/excluded, rendering reports inaccurate.

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

Reproduce the discrepancy with the two bandit -x commands from the issue and compare their scan counts. Trace the CLI exclusion-filter path to determine why ./.tox and .tox differ; done means both forms exclude the same directory and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.