You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After creating bandit config and a baseline such that bandit -c .bandit.yaml -b .bandit_baseline.json -r . passes, I added my desired pre-commit configuration:
and ran pre-commit run --all-files --show-diff-on-failure expecting it to pass.
However, it appears that the baseline does not apply when a file is passed to bandit (pre-commit works by passing staged files as arguments), so this fails.
To Reproduce
In an empty directory, create fail.py:
This ensures that the paths are passed to bandit in a similar manner to what pre-commit will do, and easily excludes untracked virtualenvs and the like.
You could also use find . -type f | sed 's:\./::' or the like and expand the exclude listing, but that seems messy.
I stand by the opinion that bandit should normalize for ./ as a prefix internally, so that you can just call bandit -r . without explicitly passing a file list and you don't get these spurious failures.
No, I've changed how the baseline is generated. The sample I provided passes filenames for the baseline exactly the way that pre-commit will pass them to the hook.
Describe the bug
After creating bandit config and a baseline such that
bandit -c .bandit.yaml -b .bandit_baseline.json -r .
passes, I added my desired pre-commit configuration:and ran
pre-commit run --all-files --show-diff-on-failure
expecting it to pass.However, it appears that the baseline does not apply when a file is passed to
bandit
(pre-commit
works by passing staged files as arguments), so this fails.To Reproduce
In an empty directory, create
fail.py
:and run bandit to create a baseline:
bandit -f json -o .baseline.json -r .
Then try running bandit with that input baseline giving
fail.py
as an argument:this fails (unexpectedly!).
If you then create a baseline from
fail.py
, you'll get a file that works:bandit -f json -o .baseline.json fail.py bandit -b .baseline.json fail.py # works!
The difference?
./fail.py
vsfail.py
:Expected behavior
With a baseline generated recursively over a repo, the
pre-commit
hook should pass.In order for this to happen, running
bandit
to lint an explicit file with a baseline generated by a recursive walk needs to work.The text was updated successfully, but these errors were encountered: