False negative: B202 unsafe `tarfile.extract()` not detected
Open
Beginner friendly
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 8.3k
- Forks
- 836
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 1
Description
Describe the bug
B202 is intended to detect unsafe tar extraction patterns (CWE-22), but the current implementation only checks for extractall calls and misses unsafe extract usage.
Reproduction steps
cat > /tmp/repro_b202_extract_fn.py <<'PY'
import tarfile
import tempfile
from pathlib import Path
def unsafe_archive_handler(filename):
target_dir = Path(tempfile.mkdtemp())
tar = tarfile.open(filename)
for member in tar.getmembers():
# Vulnerable: no validation of member.name/linkname
tar.extract(member, path=target_dir)
tar.close()
PY
bandit -r /tmp/repro_b202_extract_fn.py -t B202
Expected behavior
B202 should also detect an unsafe tarfile.extract() usage, not only extractall().
Bandit version
1.9.1 (Default)
Python version
3.14 (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 rule and run the reproduction script at /tmp/repro_b202_extract_fn.py using the reported bandit command. Compare detection of tar.extract() with the existing extractall() behavior; done means unsafe extract usage is reported without losing the current check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100