Repository navigation
fix: exact own origin for allowedOrigins lists, and open-editor over the network - #5776
alexander-akait wants to merge 2 commits into
Conversation
…the network With `allowedOrigins` set, the page's own origin is now the host and port it reached the server by, exactly, instead of its hostname on any port with the loopback names counted as one: another server's page on `localhost` could read the bundles through CORS and receive hot updates. `/webpack-dev-server/open-editor` reached through a network address now needs a same-origin `Referer` (or the hot token) when the request carries neither `Sec-Fetch-Site` nor `Origin`, which a browser omits for any `http:` page that is not on `localhost`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughAllowed-origin checks now compare exact hosts and ports, with default-port normalization. The editor-opening endpoint now requires same-origin validation and evidence that the request came from the server’s page. Tests and documentation were updated for these rules. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5776 +/- ##
=======================================
Coverage 95.79% 95.80%
=======================================
Files 6 6
Lines 5539 5596 +57
=======================================
+ Hits 5306 5361 +55
- Misses 233 235 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
I audited the security behavior of
mainafter #5770. The test drove a real browser against a dev server, with a hostile page on another loopback port and the server reached by a LAN address. It found two gaps; this PR closes both. The default setup onlocalhostbehaves exactly as before.1.
allowedOriginsas a list: the page's own origin is now exactWith a list, even
[], the page's own origin used to mean its hostname on any port, withlocalhost,127.0.0.1and[::1]counted as one. Explicit mode answers an allowed origin with an echoedAccess-Control-Allow-Origin. So any other server's page onlocalhostcould:/webpack-dev-serverassets page),It now means the host and port the request reached the server by, exactly. The scheme is not compared, so a proxy that terminates TLS in front of the server still counts. A pretend
Host(with a path or credentials) never matches.client.webSocketURLpoints elsewhere.allowedOriginsis not released yet (#5770). The release PR #5774 includes it, so please merge this one first.2.
/webpack-dev-server/open-editorreached through a network addressBrowsers send neither
Sec-Fetch-SitenorOriginfor a page that is not a secure context, which is anyhttp:page except one onlocalhost. With the server reached ashttp://192.168.x.x:8080(the defaulthostlistens on every interface), any page could load/webpack-dev-server/open-editor?fileName=/etc/hostnameas an image and launch the editor. The audit reproduced this in both"auto"and list modes.Such a request must now show where it came from:
Referer, which the overlay's ownfetchsends;Requests through
localhostare let in as before: browsers sendSec-Fetch-Sitethere, so a header-less request is a non-browser client.invalidateis unchanged (it only triggers a rebuild, and it is used by typing its URL).Not changed, already tracked in code TODOs (#5775)
"auto", a page on another loopback port can still connect to the HMR WebSocket. Real setups rely on this (a backend page on another port using HMR). The next major hands the token to every client and requires the exact origin.hostdefaults to every interface,serveIndexis on, andstatic.denyis off.Tests
Host.127.0.0.1are refused with no ACAO and no HMR; the page's own origin gets no credentials.Referer; allowed with its ownReferer,Sec-Fetch-Site: same-origin, or the token.mainalso has (IPv6, proxy, overlay snapshots), the only differences were the CLI help snapshots, updated here.harness-server-cleanuphangs in the sandbox onmainas well.localhostbehavior is unchanged.Generated by Claude Code
Summary by CodeRabbit
Security
Documentation