Unable to save ACLs and logout after upgrading from 0.7 to 0.8
Description
When I trying to save ACLs or logout after upgraded to 0.8.0, they broke with the following errors. Release notes didn't seems to mentioned any migration steps needed.
Error: Bad Request
at singleFetchAction (file:///app/build/server/index.js:14265:44)
at handleSingleFetchRequest (file:///app/build/server/index.js:14640:50)
at requestHandler (file:///app/build/server/index.js:14544:21)
at requestHandler (file:///app/build/server/index.js:14610:10)
at file:///app/build/server/index.js:14822:10
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async Object.requestListener (file:///app/build/server/index.js:5376:15)
Error: Bad Request
at singleFetchAction (file:///app/build/server/index.js:14265:44)
at handleSingleFetchRequest (file:///app/build/server/index.js:14640:50)
at requestHandler (file:///app/build/server/index.js:14544:21)
at requestHandler (file:///app/build/server/index.js:14610:10)
at file:///app/build/server/index.js:14822:10
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async Object.requestListener (file:///app/build/server/index.js:5376:15)
Error: Bad Request
at singleFetchAction (file:///app/build/server/index.js:14265:44)
at handleSingleFetchRequest (file:///app/build/server/index.js:14640:50)
at requestHandler (file:///app/build/server/index.js:14544:21)
at requestHandler (file:///app/build/server/index.js:14610:10)
at file:///app/build/server/index.js:14822:10
at async Object.requestListener (file:///app/build/server/index.js:5376:15)
Error: Bad Request
at singleFetchAction (file:///app/build/server/index.js:14265:44)
at handleSingleFetchRequest (file:///app/build/server/index.js:14640:50)
at requestHandler (file:///app/build/server/index.js:14544:21)
at requestHandler (file:///app/build/server/index.js:14610:10)
at file:///app/build/server/index.js:14822:10
at async Object.requestListener (file:///app/build/server/index.js:5376:15)
Headplane Version
v0.8.0
Headscale Version
v0.29.5
Root cause
The Error: Bad Request is React Router's action-origin guard (throwIfPotentialCSRFAttack), which runs for every non-GET single-fetch action. Its stack (singleFetchAction → handleSingleFetchRequest → requestHandler) is exactly the trace in the report. So this is not specific to ACLs or logout — every action POST is rejected, and logout simply happens to be one of them. Loaders are unaffected, which is why pages still render.
The guard compares the browser's Origin header against request.url:
- react-router 8.3.0 compared only the host:
new URL(origin).host === new URL(request.url).host. - react-router 8.3.1 tightened it in remix-run/react-router#15419 to compare the full origin (scheme + host + port). 8.4.0 carries the same code.
- Headplane 0.7.1 pinned react-router
8.3.0; 0.8.0 bumped it to8.4.0(verified by diffingv0.7.1→v0.8.0inpackage.jsonandpnpm-lock.yaml). That bump is the regression.
When Headplane runs behind a TLS-terminating reverse proxy — the documented, recommended setup — the socket to Headplane is plain HTTP, so @react-router/node builds the request URL as http://<host>/admin/... while the browser sends Origin: https://<host>. Same host, different scheme, so the guard returns a 400 that the UI renders as "Unexpected Server Error". Headplane's runtime does not consult X-Forwarded-Proto, and @react-router/node's createRequestListener doesn't expose trustProxy, so there is nothing to reconcile the two today.
I confirmed the installed [email protected] code (dist/development/lib/actions.js) and compared it with the published 8.3.0 build. This is a known upstream change that other projects have hit; upstream later fixed only the dev-server path (#15466).
Fix plan
Goal: make same-host action requests pass the schemeful check while still rejecting genuinely cross-origin submissions. No new required config.
- Align the request origin for same-host actions. When the
Originhost matches the requestHost, the request URL should use the browser's scheme. Since the host is already correct behind a proxy, this is purely a scheme reconciliation:- Preferred: construct the React Router request with the resolved scheme in a small Headplane-owned listener in
app/server/app.ts, replacing the@react-router/nodecreateRequestListener. Use@remix-run/node-fetch-server'screateRequest/sendResponse(add it as a direct dependency — it's currently only transitive) and keep passing the socket address togetLoadContextsoproxy_auth'strusted_proxy_cidrslogic is unchanged. - Minimal alternative: in
runtime/http.ts'scomposeListener, normalize the incomingOriginheader to the scheme Headplane actually sees when the Origin host equalsHost(React Router copies request headers into theRequest). Cross-host Origins are left untouched and still rejected. ~10 lines, no new deps, keeps all of@react-router/node's abort/stream handling.
- Preferred: construct the React Router request with the resolved scheme in a small Headplane-owned listener in
- Optionally honour
X-Forwarded-Proto/X-Forwarded-Hostas a complementary signal, since the docs already instruct proxies to set them. Do not enable blankettrustProxy, because@react-router/nodedoesn't forward it and doing so throughnode-fetch-serverwould change the client address and breakproxy_auth. - Optional defense in depth: set
build.allowedActionOriginsat runtime fromserver.base_url's host (React Router's documented escape hatch, per itsConfigdocs). This is a few lines but only helps whenserver.base_urlis the public URL — noteconfig.example.yamldefaults it tohttp://localhost:3000, so it is not sufficient on its own.
Files
app/server/app.ts— request listener / origin handling (shared by prod and dev, so one fix covers both).runtime/http.ts— only if we take thecomposeListenershim route.package.json/pnpm-lock.yaml— add@remix-run/node-fetch-serverif we replace the listener.tests/unit/server/...(new) — unit-test the origin-resolution helper: same-hostOrigin: https://host+Host: hostresolves tohttps;Origin: https://evil.comis not allowed.CHANGELOG.md— add a## Fixesline under# Next, in prose, closing #657.docs/configuration/index.md(Reverse Proxying) — note theX-Forwarded-Proto/Hostexpectation so proxy setups are documented end to end.
Verification
pnpm run typecheckandpnpm run lint.- New unit test for the origin helper, plus a manual check: run the production build behind a TLS-terminating proxy and confirm Save (ACL) and Logout now succeed while a cross-origin POST still returns 400.
Immediate workaround for affected users
server.base_url alone does not fix 0.8.0. Options:
- Configure the reverse proxy to rewrite the
Originrequest header to the scheme Headplane sees, e.g. nginxproxy_set_header Origin http://$host;(only the scheme differs, so this is safe). - Or terminate TLS in-process with
server.tls_cert_path/server.tls_key_path(from 0.7.0) and point the proxy at HTTPS, so the socket is genuinely HTTPS. - Or pin/downgrade
react-routerto8.3.0(not recommended long-term).
No implementation has been started yet, per the request.
Task list (3/3 completed)
- [x] Gather context on ACL save and logout flow
- [x] Identify root cause of Bad Request after 0.7->0.8 upgrade
- [x] Produce actionable plan and post via report_progress

deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
Thanks, I implement workaround "Configure the reverse proxy to rewrite the Origin request header ..." in my traefik reverse proxy labels with success!
Thanks, I implement workaround "Configure the reverse proxy to rewrite the Origin request header ..." in my traefik reverse proxy labels with success!
~~My Caddy doesn't seem to work with this workaround...~~ (Edit: It works now)
I have updated a system with headplane 0.6.1 and headscale 0.27.0. With this headplane was working in all scenarios I had.
But after updatting to heaplane 0.8.2 with headscale v0.29.7 I had the same issue as described above.
In one scenario (reverse proxy and headscale/headplane on same VM and headplane uses a different domain and port 8443) it only works with this:
proxy_set_header Origin "";
Without this seeting I get:
Error: Session cookie is empty at decodeCookie (file:///app/build/server/index.js:177816:19) at async resolve (file:///app/build/server/index.js:177896:19) at async apiForRequest (file:///app/build/server/index.js:178174:21) at async loader$16 (file:///app/build/server/index.js:178305:18)
But maybe this is not a bug but a matter of nginx configuration.
I can remove this setting by changing this:
# Preserves domain + port (:8443) so login/CSRF works
# proxy_set_header Host $host;
proxy_set_header Host $http_host;
Here the complete working configuration:
location / {
proxy_pass http://172.18.0.2:3000;
# Preserves domain + port (:8443) so login/CSRF works
proxy_set_header Host $http_host;
# Tells Headplane the original client connection is HTTPS
proxy_set_header X-Forwarded-Proto $scheme;
# Passes client IP for accurate logs
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
# Disables proxy buffering so real-time events stream immediately
proxy_buffering off;
proxy_cache off;
# Extends timeout so idle streams aren't killed prematurely (e.g. 24h)
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
# Required for persistent SSE & WebSocket streams
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}