Skip to content

Fix: secure tar extraction issue#5587

Merged
mollyheamazon merged 2 commits into
aws:masterfrom
mollyheamazon:fix/tar-extraction
Feb 27, 2026
Merged

Fix: secure tar extraction issue#5587
mollyheamazon merged 2 commits into
aws:masterfrom
mollyheamazon:fix/tar-extraction

Conversation

@mollyheamazon

Copy link
Copy Markdown
Contributor

Fixes #5560

Summary

Fixes three security flaws in _repack_model.py that prevented tar extraction safety checks from working, allowing potential path traversal attacks.

Changes

  1. Fixed iterator bug: Changed _get_safe_members(tar) to _get_safe_members(tar.getmembers(), base) - iterating over TarFile doesn't yield TarInfo
    objects, causing checks to fail

  2. Fixed base directory: Pass actual extraction path instead of current working directory - checks were validating against wrong location

  3. Fixed path validation: Use os.path.commonpath() instead of startswith() - prevents bypass via paths like /tmp/x2 escaping base /tmp/x

Impact

Without these fixes, malicious tar archives could write files outside the intended extraction directory (tar slip attack).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@mollyheamazon mollyheamazon merged commit a6303a4 into aws:master Feb 27, 2026
14 of 17 checks passed
Evan-W-ang added a commit to Evan-W-ang/sagemaker-python-sdk that referenced this pull request Jun 8, 2026
* Fix: secure tar extraction issue

* Update unit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancements Needed for Secure Tar Extraction

2 participants