Skip to content

r.unpack, v.unpack: Refuse to extract archives without a tarfile filter - #7701

Merged
cwhite911 merged 1 commit into
OSGeo:mainfrom
cwhite911:unpack-tarfile-fallback
Jul 14, 2026
Merged

cwhite911 merged 1 commit into
OSGeo:mainfrom
cwhite911:unpack-tarfile-fallback

Conversation

@cwhite911

Copy link
Copy Markdown
Contributor

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 the data filter 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.extension and grass.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 an r.pack/r.unpack round trip, both exercising the filter="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.

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.
@github-actions github-actions Bot added vector Related to vector data processing raster Related to raster data processing Python Related code is in Python libraries module general labels Jul 14, 2026
@cwhite911
cwhite911 merged commit ec57867 into OSGeo:main Jul 14, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

general libraries module Python Related code is in Python raster Related to raster data processing vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants