Commit b6b86d3
authored
Strengthen path traversal protection in archive extraction (#295)
## Summary
Enhance the `safeJoin` function in the self-update archive extraction
logic to explicitly reject `".."` path segments, preventing potential
path traversal attacks even when path normalization might be bypassed.
## Changes
- **Explicit `".."` segment rejection**: Added validation to detect and
reject any `".."` path segment in archive entries, including those using
backslash separators on Windows
- **Normalized path checking**: Convert backslash separators to forward
slashes before splitting and validating path segments
- **Expanded test coverage**: Added test cases covering:
- Bare `".."` entries
- Mixed path traversal patterns (`a/../b`, `a/..`)
- Backslash-separated traversal attempts (`a\\..\\..\escape`,
`..\escape`)
## Implementation Details
The fix normalizes the archive entry name by converting all backslashes
to forward slashes, then validates each path segment individually. Any
segment matching `".."` is rejected with a clear error message. This
defense-in-depth approach complements the existing `filepath.Clean`
validation and ensures traversal attempts cannot slip through regardless
of path separator style or normalization edge cases.
https://claude.ai/code/session_01GJyEVeydpmtcNCqKHfhiEu
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Small, additive hardening in archive path validation with no change to
successful extraction paths; lowers zip-slip risk rather than
introducing new behavior.
>
> **Overview**
> Hardens **`safeJoin`** in beacon self-update archive extraction by
rejecting any path segment equal to **`..`** before the existing
`filepath.Clean` containment check.
>
> Archive entry names are normalized (`\` → `/`), split on `/`, and
rejected with a dedicated traversal error if any segment is **`..`**,
including Windows-style backslash patterns.
**`TestSafeJoinRejectsTraversal`** gains cases for bare **`..`**, mixed
**`a/../b`** / **`a/..`**, and backslash traversal strings.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
cbae2c7. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->2 files changed
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
0 commit comments