Repository navigation
Conversation
The CORS policy allowed `http://localhost:` and nothing else. It was written when the server bound every interface and was reached by name; since it binds the loopback, `listenHost()` is an address rather than a name, so the URL the application opens in the browser is `http://127.0.0.1:8080`. A browser sends an `Origin` header on a POST even when it is same-origin, so the page the application had just opened was refused by the application that opened it. The event bus handshake is a POST: every SockJS request answered `403 CORS Rejected - Invalid origin`, the channel never opened, and the UI retried for as long as it stayed open while showing the user that device monitoring was down. Nothing about it was intermittent -- it could not work at all -- and it was reported from a browser before it was reproduced with curl. The rule is that the loopback is one host under several names, so all three are accepted and the port stays open-ended, which the development server needs. It is not widened to `*`: this API has no authentication, and whatever a page on another origin could reach here, it could reach in the browser of anyone who visits it. That refusal is asserted with the same weight as the acceptance, since a policy that allowed everything would pass the nominal cases on its own.
…nevalentinHA#46 Reworked after the review on antoinevalentinHA#68. The previous commit widened the any-port pattern to every spelling of the loopback; this replaces it with the shape agreed in antoinevalentinHA#46: the allowed origin is derived from listenHost() and LISTEN_PORT, so exactly http://localhost:8080 and http://127.0.0.1:8080 are answered, and no other port. That fixes the real failure, a user who types 127.0.0.1:8080 getting reads that work and every state-changing call refused, and closes the port wildcard that let any page on a localhost origin drive the API. The development server needs no exception. src/setupProxy.js carries /eventbus to the backend, WebSocket included, and rewrites the Origin it forwards to the backend's own; the package.json proxy already does that for plain HTTP requests, but not on the WebSocket upgrade. REACT_APP_EVENTBUS_ORIGIN is no longer needed and is gone. CorsOriginTest keeps its near-miss refusals and adds the loopback on a foreign port (http://localhost:1, :3000, :8081, :80800) and https on the right port. Two of its four tests fail against the old pattern.
lgnap
force-pushed
the
fix/cors-loopback-origin
branch
from
November 19, 2026 15:31
36cc4f3 to
57b3f60
Compare
Author
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.
What
Reworked along the lines settled in #46, after the review on #68.
The CORS policy was
http://localhost:.*. It refusedhttp://127.0.0.1:8080, the address the server binds: a user who types it gets reads that work and every state-changing call refused, because a browser sendsOriginon a POST even when it is same-origin. And it trusted every port of the machine, so any page on alocalhostorigin could drive this unauthenticated API. (The first version of this PR said the application opens the browser at127.0.0.1; it does not,MainVerticleopenshttp://localhost:8080. That premise was wrong and is gone.)The allowed origin is now derived from what the server serves:
MainVerticle.allowedOrigins()builds it fromlistenHost()andLISTEN_PORT, so exactlyhttp://localhost:8080andhttp://127.0.0.1:8080are answered, and nothing else.[::1]is not listed: the server binds an IPv4 address, so nothing reaches it under that name.The development server. No exception and no
env=devbranch:src/setupProxy.jscarries/eventbusto the backend, WebSocket included, and rewrites theOriginit forwards to the backend's own. Thepackage.jsonproxy already rewritesOriginon plain HTTP requests, but not on the WebSocket upgrade, which is why the entry is needed.REACT_APP_EVENTBUS_ORIGINis no longer used and is removed fromApp.js.http-proxy-middlewareis the copy react-scripts 3.0.1 ships (0.19.2), not a new dependency.Not done on purpose:
x-requested-withis left as it is, as agreed in #46.Tests
CorsOriginTest(4 tests, realMainVerticle):localhost:8080and127.0.0.1:8080answered; foreign hosts, the near-miss spellings andhttps://localhost:8080refused; the loopback on a foreign port refused —http://localhost:1,:3000,127.0.0.1:3000,:8081,:80800. Against the old pattern, 2 of the 4 fail (127.0.0.1:8080refused,localhost:1answered).setupProxy.test.js(4 tests):/eventbusonly, to127.0.0.1:8080,ws: true, theOriginrewrite on HTTP and WebSocket requests, noOriginadded where there was none. JavaScript suite: 61 tests.Measured (Linux, backend with
env=dev,yarn starton :3000)Not measured: Windows, and a browser session end to end (the table above is
curl).