Commit 2c0bf8d
fix(static): use path.Clean for fs.FS resolution to block Windows backslash bypass
CI on windows-latest caught that StaticDirectoryHandler resolved the static file
name with filepath.Clean + filepath.ToSlash, which is OS-specific. An encoded
backslash (%5C) decodes to a literal '\' that the router does not treat as a
separator (it matches on the raw/canonical path), but on Windows filepath.Clean
then interprets '\' as a path separator and resolves a file across a boundary the
route never authorized -- serving /admin%5Csecret.txt as admin/secret.txt (the
GHSA-pgvm-wxw2-hrv9 Windows backslash traversal class). On Linux '\' stays literal,
which is why local tests passed.
fs.FS paths are always forward-slash, so use path.Clean (OS-independent), matching
what middleware/static.go already does. The HasEncodedPathSeparator guard still
covers the %2F case where the param stays percent-encoded.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 840cb19 commit 2c0bf8d
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
606 | 607 | | |
607 | 608 | | |
608 | 609 | | |
609 | | - | |
610 | | - | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
611 | 615 | | |
612 | 616 | | |
613 | 617 | | |
| |||
0 commit comments