prevent path traversal via chmod and mtime in zip unpacking - #5499
Merged
ivankravets merged 3 commits intoAug 22, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens archive extraction in platformio/package/unpack.py by extending the existing TAR “bad path” guardrails to ZIP extraction, specifically to prevent applying chmod/mtime to paths that escape the destination directory.
Changes:
- Lifted
resolve_path/is_bad_pathintoBaseArchiverfor reuse. - Added ZIP entry validation before extraction to block paths resolving outside
dest_dir. - Ensured ZIP extraction uses a normalized destination path when performing safety checks.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+134
to
+140
| if self.is_bad_path(item.filename, dest_dir): | ||
| return click.secho( | ||
| "Blocked insecure item `%s` from ZIP archive" % item.filename, | ||
| fg="red", | ||
| err=True, | ||
| ) | ||
| return super().extract_item(item, dest_dir) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Member
|
Thanks for the PR! |
ivankravets
added a commit
that referenced
this pull request
Aug 22, 2026
… path traversal entries // Pull #5499
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.
ZIPArchiverapplied chmod and mtime to the raw archive entry name joined onto the destination directory, so an entry like../namecould change permissions (including setuid) on a file outside the extraction directory. the tar path already guards this withis_bad_path, the zip path did notthis lifts
is_bad_path/resolve_pathto the base archiver and blocks zip entries that resolve outside the destination, matching the existing tar behavior