Repository navigation
r.unpack, v.unpack: Refuse to extract archives without a tarfile filter - #7701
Merged
Merged
Conversation
The pre-PEP 706 fallback extracted archives with a bare extractall(), which allows path traversal outside the target directory. The 'data' filter is available in Python 3.11.4, 3.12, and newer, so make its absence a fatal error instead of extracting unsafely after a warning. Apply the same to the identical fallbacks in g.extension and grass.utils.download. Fixes 2 Bandit B202 (tarfile_unsafe_members) alerts.
petrasovaa
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the 2 open Bandit B202 (
tarfile_unsafe_members, error severity) code scanning alerts in r.unpack and v.unpack.The alerts fire on the pre-PEP 706 fallback branch, which extracted archives with a bare
extractall()after only a warning. A crafted pack file could write outside the extraction directory. Since the minimum supported Python is now 3.11 (#7684) and thedatafilter is available in 3.11.4+ and 3.12+, the only Pythons that reach the fallback are outdated 3.11 micro releases, so refuse to extract there with a fatal error instead of proceeding unsafely.The same fallback pattern exists (unflagged) in
g.extensionandgrass.utils.download; this applies the identical change there for consistency.Verified by running the v.unpack gunittest (
testsuite/test_v_unpack.py, passes against nc_spm) and anr.pack/r.unpackround trip, both exercising thefilter="data"path, plus a local bandit 1.9.4 run confirming the B202 findings are gone.This is part of a larger effort to work through the open code scanning alerts, grouped into small PRs by issue type.
Written with the assistance of Claude Code.