fix(http): reject percent-encoded backslashes in serveDir() paths - #7321
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7321 +/- ##
==========================================
+ Coverage 95.00% 95.03% +0.02%
==========================================
Files 617 617
Lines 51674 51654 -20
Branches 9326 9365 +39
==========================================
- Hits 49093 49089 -4
+ Misses 2038 2022 -16
Partials 543 543 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Bun 1.4.2 crashes when constructing a node:worker_threads Worker (TypeError: undefined is not an object (evaluating 'this._events')), which fails this test on every PR.
This was referenced Sep 17, 2026
Contributor
|
@bartlomieju Thank you for your work on this! I just created #7325 to address an issue with double-separators in the containment check. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
serveDir() validates request paths using POSIX semantics (posixNormalize and
a /-based dotfile check), but resolves them with the platform-aware join().
A percent-encoded backslash (%5C) survives URL parsing, is reintroduced by
decodeURIComponent(), and passes the POSIX-based checks as an ordinary
character — yet on Windows join() treats it as a path separator. As a result,
paths like /%5C.dotfile or /sub%5C..%5C..%5Cfile could resolve to dotfiles or
to files outside fsRoot on Windows.
Since the URL parser maps raw backslashes to forward slashes, a backslash can
only reach this code via percent-encoding and has no legitimate meaning in a
served path, so such requests are now rejected with 404 before any filesystem
access. As defense in depth, the final resolved path is also verified to stay
within fsRoot.
This also adds an unstable dotfiles option to serveDir(), mirroring the
serve-static-style API: "ignore" (the default) responds with 404, "deny"
responds with 403, and "allow" serves dotfiles and shows them in directory
listings. It takes precedence over the existing showDotfiles boolean, whose
behavior is unchanged.