Skip to content

Sign out to /login, not a cross-host hop - #385

Merged
neuromechanist merged 1 commit into
stagingfrom
fix/logout-redirect-cross-host
Sep 30, 2026
Merged

neuromechanist merged 1 commit into
stagingfrom
fix/logout-redirect-cross-host

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Problem

Pressing Sign out ends the session but leaves the person on the same page.

Cause

The sign-out form POSTs to /api/auth/logout from app.nemar.org, and the handler answered 303 -> /. The logout response clears the session cookie, so the follow-up GET / carries none, and since / is a marketing route the middleware answers 301 -> https://nemar.org/.

That last hop is cross-origin, and the page's CSP has form-action 'self'. Chrome applies form-action to every hop of a form-submission redirect chain, so it refuses the hop. The cookie is already cleared by then, so the account is signed out and the page does not move.

Checked against production over HTTP (no cookie):

  • POST app.nemar.org/api/auth/logout -> 303, location: /, cookie cleared, CSP ends in form-action 'self'
  • GET app.nemar.org/ -> 301, location: https://nemar.org/
  • GET app.nemar.org/login -> 200

The browser refusal itself is inferred from Chrome's documented form-action behavior; it was not reproduced in a signed-in browser.

Change

  • SIGNED_OUT_PATH = "/login" in src/lib/auth.ts, with the reason next to it. /login is an app route, so the chain ends in one hop on the app host.
  • src/pages/api/auth/logout.ts uses it for both the dev and production HTML branches.
  • src/lib/host.test.ts pins the invariant: SIGNED_OUT_PATH is an app route and is not cross-host redirected without a session, and / still is.

The other option was to add https://nemar.org to form-action, which widens the CSP on every page for one redirect. Not taken.

Testing

  • bun run lint, bun run typecheck (0 errors), bun run test (2633 passed)
  • astro dev: form POST returns 303 -> /login, cookie cleared, /login is 200
  • Production after promotion. test.nemar.org runs single-host mode, so the cross-host redirect that causes this cannot occur there (website#212); staging cannot show the before or after.

The form POST 303'd to /, which the app host 301s to nemar.org once the
cookie is cleared. CSP form-action 'self' blocks that cross-origin hop
in Chrome, so the session ended but the page never moved.

Add SIGNED_OUT_PATH (/login, an app route) and a host test pinning it.
Unit tests, lint, typecheck pass; handler checked under astro dev.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit b6d8df7 into staging Sep 30, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the fix/logout-redirect-cross-host branch September 30, 2026 09:23
neuromechanist added a commit that referenced this pull request Sep 30, 2026
* test: pin the sign-out redirect in logout.ts

* docs: mark the #385 Chrome cause as inferred
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.

1 participant