Skip to content

A-1533: harden cache target path validation and extraction - #4102

Draft
zhming0 wants to merge 1 commit into
mainfrom
a-1533-absolute-target-paths
Draft

A-1533: harden cache target path validation and extraction#4102
zhming0 wants to merge 1 commit into
mainfrom
a-1533-absolute-target-paths

Conversation

@zhming0

@zhming0 zhming0 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Part of A-1533 (multi-PR change).

Safety hardening for cache save/restore path handling. No behavior change for supported paths (~/..., absolute under $HOME, CWD-relative); unsupported or unsafe forms now fail early with clear errors instead of failing late or behaving unsafely.

  • Reject absolute paths outside $HOME at mapping time (previously failed late in BuildArchive), ~/../ escapes, parent-relative paths escaping CWD, and Windows rooted/drive-relative paths
  • Fix home-prefix matching so a sibling like /home/user2 is not treated as under /home/user
  • Harden extraction: whole-component entry matching (entry cache2/x no longer matches target cache) and zip-slip containment checks for untrusted archive entries
  • Validate all target paths in Save and Restore before any download or destructive cleanup
  • Cleanup refuses filesystem roots, $HOME, top-level dirs, and CWD or its ancestors
  • Path validation/cleanup moved into internal/cache/paths.go

Support for absolute target_paths outside $HOME will land in a follow-up PR, implemented via an archive manifest format change.

@zhming0
zhming0 force-pushed the a-1533-absolute-target-paths branch from b1e18ce to 17239ce Compare July 20, 2026 14:58
@zhming0 zhming0 changed the title A-1533: support absolute cache target_paths outside $HOME Harden cache target path validation and extraction Jul 20, 2026
@zhming0 zhming0 changed the title Harden cache target path validation and extraction A-1533: harden cache target path validation and extraction Jul 21, 2026
Part of A-1533 (multi-PR change). Validate cache target paths up front
and reject unsupported or unsafe forms with clear errors instead of
failing late or behaving unsafely:

- Reject absolute paths outside $HOME at mapping time (previously
  failed late in BuildArchive), ~/../ escapes, parent-relative paths
  escaping CWD, and Windows rooted/drive-relative paths
- Fix home-prefix matching so a sibling like /home/user2 is not
  treated as under /home/user
- Harden extraction: whole-component entry matching (entry cache2/x no
  longer matches target cache) and zip-slip containment checks for
  untrusted archive entries
- Validate all target paths in Save and Restore before any download or
  destructive cleanup
- Cleanup refuses filesystem roots, $HOME, top-level dirs, and CWD or
  its ancestors
- Move path validation/cleanup into internal/cache/paths.go

Support for absolute target_paths outside $HOME will land in a
follow-up PR via an archive manifest format change.
@zhming0
zhming0 force-pushed the a-1533-absolute-target-paths branch from 17239ce to cda6797 Compare July 21, 2026 05:21
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.

1 participant