Skip to content

prevent path traversal via chmod and mtime in zip unpacking - #5499

Merged
ivankravets merged 3 commits into
platformio:developfrom
knQzx:fix/zip-path-traversal-chmod
Aug 22, 2026
Merged

prevent path traversal via chmod and mtime in zip unpacking#5499
ivankravets merged 3 commits into
platformio:developfrom
knQzx:fix/zip-path-traversal-chmod

Conversation

@knQzx

@knQzx knQzx commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

ZIPArchiver applied chmod and mtime to the raw archive entry name joined onto the destination directory, so an entry like ../name could change permissions (including setuid) on a file outside the extraction directory. the tar path already guards this with is_bad_path, the zip path did not

this lifts is_bad_path/resolve_path to the base archiver and blocks zip entries that resolve outside the destination, matching the existing tar behavior

@ivankravets
ivankravets requested a lite review from Copilot August 22, 2026 12:05
@ivankravets ivankravets added this to the 6.2.0 milestone Aug 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_path into BaseArchiver for 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 thread platformio/package/unpack.py Outdated
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)
ivankravets and others added 2 commits August 22, 2026 15:11
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@ivankravets
ivankravets merged commit fe7c14a into platformio:develop Aug 22, 2026
26 of 30 checks passed
@ivankravets

Copy link
Copy Markdown
Member

Thanks for the PR!

ivankravets added a commit that referenced this pull request Aug 22, 2026
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.

3 participants