Skip to content

Harden polyserve against dotfile disclosure and DNS rebinding - #3863

Merged
rictic merged 3 commits into
masterfrom
fix-polyserve-dotfiles-host-check
Dec 1, 2026
Merged

rictic merged 3 commits into
masterfrom
fix-polyserve-dotfiles-host-check

Conversation

@rictic

@rictic rictic commented Nov 30, 2026

Copy link
Copy Markdown
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.
@rictic
rictic requested a review from dfreedm November 30, 2026 23:35
Comment thread packages/polyserve/src/make_app.ts Resolved
Comment thread packages/polyserve/src/start_server.ts Resolved

@dfreedm dfreedm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 allows localhost, 127.0.0.1, [::1], os.hostname(), and options.hostname. If someone binds to 0.0.0.0 or :: 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 from os.networkInterfaces() when hostname is 0.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
rictic enabled auto-merge December 1, 2026 00:10
@rictic
rictic merged commit 90898b9 into master Dec 1, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants