Repository navigation
Harden polyserve against dotfile disclosure and DNS rebinding - #3863
Merged
Merged
Conversation
rictic
commented
Nov 30, 2026
Contributor
- Pass dotfiles: 'deny' to send() in start_server.ts and make_app.ts so requests for dotfiles and dot-directories (such as .git/* or .env) return HTTP 403 instead of serving files.
- Pass an explicit root to send() in make_app.ts so requests stay confined to root or componentDir and projects located under an ancestor dot-directory continue to serve normally.
- Validate the HTTP Host header against loopback (localhost, 127.0.0.1, [::1]), os.hostname(), and the configured hostname in getApp(), startControlServer(), and createServer(), returning HTTP 403 for missing, malformed, or untrusted Host headers.
- Add unit tests for dotfile denial, ancestor dot-directories, path traversal, package root redirect/index, and Host header validation.
- Pass dotfiles: 'deny' to send() in start_server.ts and make_app.ts so requests for dotfiles and dot-directories (such as .git/* or .env) return HTTP 403 instead of serving files. - Pass an explicit root to send() in make_app.ts so requests stay confined to root or componentDir and projects located under an ancestor dot-directory continue to serve normally. - Validate the HTTP Host header against loopback (localhost, 127.0.0.1, [::1]), os.hostname(), and the configured hostname in getApp(), startControlServer(), and createServer(), returning HTTP 403 for missing, malformed, or untrusted Host headers. - Add unit tests for dotfile denial, ancestor dot-directories, path traversal, package root redirect/index, and Host header validation.
dfreedm
approved these changes
Dec 1, 2026
dfreedm
left a comment
Member
There was a problem hiding this comment.
LGTM overall — clean, well-scoped hardening for both dotfile/path-traversal confinement and DNS rebinding, with solid test coverage (including ancestor dot-directories, URL-encoded paths, IPv6 Host headers, and appMapper routes).
One non-blocking thought to consider:
- Wildcard bind addresses (
--hostname 0.0.0.0/::):makeHostAllowlist()currently only allowslocalhost,127.0.0.1,[::1],os.hostname(), andoptions.hostname. If someone binds to0.0.0.0or::to test from a phone/VM/LAN machine via a local interface IP (e.g.http://192.168.x.x:8081), requests will now return 403. If you want to preserve that workflow, adding local interface IPs fromos.networkInterfaces()whenhostnameis0.0.0.0/::would allow LAN IP access while still blocking DNS rebinding from external domains.
Fine to merge as-is if that's intentional.
When polyserve is explicitly started with a wildcard hostname (0.0.0.0 or ::), populate the Host allowlist with local interface addresses from os.networkInterfaces() (IPv4 for 0.0.0.0; IPv4 and IPv6 for ::) so LAN, phone, and VM clients can still connect by IP while external domains remain blocked against DNS rebinding.
rictic
enabled auto-merge
December 1, 2026 00:10
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.