#7317: fix(security): harden zip extraction and hook token comparison
gateway
agents
## Summary
Two security hardening improvements identified during code review.
### 1. Zip Extraction Path Boundary Fix
**Issue:** The existing `startsWith()` check for zip entry paths can be bypassed by sibling directories:
- `destDir` = `/tmp/extract`
- `outPath` = `/tmp/extract2/malicious.txt`
- `outPath.startsWith(destDir)` = `true` ❌
**Fix:** Use `path.relative()` to properly check containment. A path escapes if the relative path starts with `..` or is absolute.
### 2. Hook Token Timing-Safe Comparison
**Issue:** JavaScript `!==` for string comparison returns early on first character mismatch, creating a timing oracle.
**Fix:** Use `crypto.timingSafeEqual()` for constant-time comparison, preventing timing attacks on hook authentication tokens.
## Testing
Added two test cases for zip path traversal scenarios:
- Basic `../` traversal rejection
- Sibling directory prefix bypass rejection
## Risk
Low — both changes are defensive hardening with minimal behavior change for legitimate use cases.
Most Similar PRs
#7616: Harden zip extraction against path traversal
by lawyered0 · 2026-02-03
69.9%
#9529: security(archive): validate entries against path traversal (Zip Slip)
by leszekszpunar · 2026-02-05
66.4%
#23294: fix(security): OC-201 Hook Transform RCE - Symlink-Safe Path Contai...
by aether-ai-agent · 2026-02-22
64.6%
#13144: harden archive extraction, auth tokens, hook transforms, and queue ...
by qxlsz · 2026-02-10
64.6%
#5649: fix(security): harden file permissions and header merging
by sfo2001 · 2026-01-31
64.4%
#20796: fix(security): OC-22 prevent Zip Slip and symlink following in skil...
by aether-ai-agent · 2026-02-19
61.7%
#11710: fix: security hardening — exec blocking, auth validation, timing-sa...
by zendizmo · 2026-02-08
60.7%
#13254: fix: harden archive extraction and plugin update rollback
by lawyered0 · 2026-02-10
59.7%
#19021: fix(hooks): reject path traversal in hook pack manifest entries dur...
by moxunjinmu · 2026-02-17
59.4%
#21964: Security: harden gateway and plugin trust boundaries
by Elormyevu · 2026-02-20
59.4%