Commit 1525370
authored
Fix prefix-boundary hole in filer root-escape checks (#5497)
## Why
Found during a full-repo review of the CLI. All filers guard against
relative paths escaping their root, but the guard in
`libs/filer/workspace_root_path.go` and `libs/filer/local_root_path.go`
was a bare string prefix check. A path that resolves to a sibling
directory sharing the root as a name prefix slipped through: with root
`/Users/me/proj`, joining `../proj-evil/x` resolves to
`/Users/me/proj-evil/x`, which passes `strings.HasPrefix`. Every filer
(workspace files, DBFS, UC volumes, local) shares these helpers, and
`bundle init` templates write template-author-controlled paths through
them.
## Changes
Before, a joined path only had to start with the root string; now it
must either be exactly the root or extend it past a separator boundary.
- `WorkspaceRootPath.Join` and `localRootPath.Join` compare against the
root with a trailing separator and explicitly allow the exact-root
result. Joins like `ReadDir(".")` resolve to exactly the root and keep
working.
- Filers rooted at `/` (used by the `fs` commands) keep working: the
separator is only appended when the cleaned root does not already end in
one. Same for Windows drive roots like `C:\`.
- The unrooted local filer (`NewLocalRootPath("")`, used by `fs` for
local paths) keeps accepting any path.
## Test plan
- [x] Added sibling-prefix escape cases (`../path-evil`,
`../path-evil/x`, `../pathx`) to
`libs/filer/workspace_root_path_test.go` and
`libs/filer/local_root_path_test.go` (Unix and Windows variants); these
fail without the fix
- [x] Added escape-and-re-enter cases asserting `../path/x` still joins
under the root
- [x] Added `TestLocalRootPathEmptyRoot` covering the unrooted local
filer passthrough
- [x] Existing exact-root cases (`Join("")`, `Join(".")`, `Join("/")`)
pass unchanged
- [x] `go test ./libs/filer/` passes
- [x] `go test ./libs/template/... ./libs/sync/...` (direct consumers of
these helpers) passes
- [x] `./task fmt-q`, `./task lint-q`, `./task checks` pass
This pull request and its description were written by Isaac.1 parent 5d85057 commit 1525370
4 files changed
Lines changed: 82 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
23 | 37 | | |
24 | 38 | | |
25 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| |||
78 | 83 | | |
79 | 84 | | |
80 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
81 | 96 | | |
82 | 97 | | |
83 | 98 | | |
| |||
128 | 143 | | |
129 | 144 | | |
130 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
131 | 161 | | |
132 | 162 | | |
133 | 163 | | |
| |||
140 | 170 | | |
141 | 171 | | |
142 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| |||
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
80 | 95 | | |
81 | 96 | | |
82 | 97 | | |
| |||
0 commit comments