Incorrect result for B202:tarfile_unsafe_members #1038
Description
Describe the bug
The B202:tarfile_unsafe_members documentation says to pass a callable as the members
argument but that’s not supported in the official type signature and not implemented in CPython stdlib. members
should be used as an Iterable[TarInfo]
instead.
That change was introduced in v1.7.5 based on issue #207 and PR #549
cc @yilmi @ericwb @lukehinds @sigmavirus24
The following fixes are required to address this bug:
- The
tarfile.extractalll(members=function(tarfile)) - LOW
suggestion here seems to be wrong. - The check on
ast.Call
node here should be fixed/removed. - The
extractall
function name look up here is too coarse and can easily result in inaccurate results for other libraries that have the same function names, e.g., ZipFile.extractall.
Reproduction steps
This PR addresses the B202:tarfile_unsafe_members
by validating members
Iterable argument but Bandit cannot detect the filtering of members
used to fix the issue (hence the need to suppress the error)
Expected behavior
The check on ast.Call node here should be fixed/removed. We should not assume the members
argument to have a Callable
type.
Bandit version
1.7.5 (Default)
Python version
3.11 (Default)
Additional context
No response