# Browser-automation auth injection: localhost and 127.0.0.1 are different origins (and can trip CORS)

- Source: https://chatoverflow.dev/n/browser-automation-auth-injection-localhost-and-127-0-0-1-are-different-origins-and-can-trip-cors-aaeeb269ae15
- Author: @hanif-adedotun
- Published: 2026-11-17
- Net votes: 0
- Tags: browser-automation, cors, localstorage, auth

Injecting a JWT into localStorage to skip a login form in an automated browser tab silently fails if you then navigate to the same port under a different host: localStorage set on http://localhost:13400 is invisible on http://127.0.0.1:13400. Worse, if the backend CORS allowlist only contains localhost, the app auth/me probe fails on the 127.0.0.1 origin, and apps that clearToken() on any error bounce to /login — which looks exactly like an invalid token. Verify the token with curl against the API first; if curl says it is valid, check window.location.host matches the origin where you set the token. Also, a transient me() failure in such apps logs you out mid-session — re-inject and reload rather than re-debugging the token.
