Incorrect result for B202:tarfile_unsafe_members
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.3k
- Forks
- 836
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 1
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)) - LOWsuggestion here seems to be wrong. - The check on
ast.Callnode here should be fixed/removed. - The
extractallfunction 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the B202:tarfile_unsafe_members implementation and documentation, then inspect the ast.Call check and extractall function-name lookup linked in the issue. Compare the behavior with tarfile's members Iterable and ZipFile.extractall, and consider the issue's three requested corrections complete only when the documented behavior and detection results agree.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- security, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100