#7616: Harden zip extraction against path traversal
## Summary\n- prevent zip-slip path traversal by tightening destDir checks\n- add a regression test for malicious zip entries\n\n## Testing\n- pnpm vitest run src/infra/archive.test.ts\n
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR tightens zip extraction path validation to mitigate zip-slip path traversal by ensuring resolved output paths stay within the destination directory, and adds a regression test covering a malicious `../` zip entry. It also extends `formatRelativeTime` to support future timestamps ("in Xm", "Tomorrow", etc.) and adds unit tests for both past and future formatting.
These changes fit into the existing `src/infra/archive.ts` extraction helper used by plugin/hook installation flows, and into the `src/utils/time-format.ts` helper used for human-readable time strings in the CLI/TUI.
<h3>Confidence Score: 3/5</h3>
- Reasonably safe to merge, but the zip-slip guard may still be fragile if callers pass non-normalized destination paths.
- The changes are small and well-covered by a regression test, but the current prefix-based containment check relies on string comparisons against `destDir` as provided, which can be bypassed or misbehave when `destDir` is relative or otherwise not normalized. The future-time formatting change is low risk but has some edge-case rounding behavior to double-check against UX expectations.
- src/infra/archive.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#9529: security(archive): validate entries against path traversal (Zip Slip)
by leszekszpunar · 2026-02-05
80.3%
#13144: harden archive extraction, auth tokens, hook transforms, and queue ...
by qxlsz · 2026-02-10
79.3%
#20424: Fix plugin extension path traversal in discovery/install
by markmusson · 2026-02-18
76.6%
#5649: fix(security): harden file permissions and header merging
by sfo2001 · 2026-01-31
72.9%
#7085: test: skip flaky workspace-paths & safe-bins tests on non-Linux/CI ...
by ThinkIbrokeIt · 2026-02-02
72.6%
#20496: test(utils): add comprehensive unit tests for utility functions
by masifislamm · 2026-02-19
72.1%
#23473: Hooks/Plugins: enforce discovery root containment
by bmendonca3 · 2026-02-22
71.6%
#13848: fix(test): normalize paths in source-display test for windows
by gengmao · 2026-02-11
71.6%
#10745: feat: Security improvements and Windows compatibility fixes
by lluviaoscuradeldoce-design · 2026-02-06
71.3%
#8124: fix(browser): add path validation for file upload and download
by yubrew · 2026-02-03
71.2%