fix(auth): require a same-origin POST to delete an account (H1 #3906522) - #2222
Open
Gr1dlock wants to merge 1 commit into
Open
fix(auth): require a same-origin POST to delete an account (H1 #3906522)#2222Gr1dlock wants to merge 1 commit into
Gr1dlock wants to merge 1 commit into
Conversation
`/api/auth/delete-account` was mounted as GET and gated solely on the presence of an Auth0 session cookie. That cookie is `SameSite=Lax` (SDK default; no `session.cookie` override in `lib/auth0.ts`), so the browser attaches it to cross-site top-level navigations — any attacker page could irreversibly delete a logged-in developer's Auth0 identity with a single `<a href>`, `window.open` or meta-refresh. `proxy.ts` passes `/api/auth/*` through untouched and no edge control fronts the host, so the handler is the only place this can be stopped. - Mount the route on POST only. `Lax` never sends the cookie on a cross-site POST, and GET now returns 405 — which also closes the reporter's first-party `/api/auth/login?returnTo=/api/auth/delete-account` delivery variant, since the post-login redirect lands as a GET. - Add `api/helpers/csrf.ts`: reject anything the browser does not report as same-origin, falling back to an `Origin` allow-list check and failing closed when neither header is present. This is the layer that survives a future change to the cookie's `SameSite` attribute. - Return 204 instead of a 307 to `/api/auth/logout`: the caller is now a `fetch()`, and a 307 would make it replay the POST against logout. The two dialogs share `deleteAuth0Identity()` and drive the logout navigation themselves, so a failed Auth0 deletion now surfaces as an error toast instead of rendering a raw JSON 500. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
PR Type
Description
/api/auth/delete-accountwas mounted as GET (app/api/auth/delete-account/route.ts) and gated solely on the presence of an Auth0 session cookie before calling the irreversiblemanagementClient.users.delete(); that cookie isSameSite=Lax(SDK v4 default atabstract-session-store.js:14—lib/auth0.tssets nosession.cookieoverride), and Lax cookies ride cross-site top-level navigations, so any attacker page could destroy a logged-in developer's Auth0 identity with a single link,window.openor meta-refresh (HackerOne #3906522) — the legitimate UI flow was itself a top-level GET navigation, so the attack was just the real flow triggered from someone else's page.proxy.ts:370returnsauthResfor all of/api/auth/*before any guard and no edge control fronts the host, so the handler is the only place this can be stopped.The route is now POST-only (Lax never sends the cookie on a cross-site POST; GET returns 405, which also closes the reporter's first-party
/api/auth/login?returnTo=%2Fapi%2Fauth%2Fdelete-accountdelivery variant since the post-login redirect lands as a GET) and is gated by a newapi/helpers/csrf.tsguard that requiresSec-Fetch-Site: same-origin, falls back to anOriginallow-list, and fails closed when neither header is present — the guard is the layer that survives a future change to the cookie'sSameSiteattribute. It returns 204 instead of the old 307 to/api/auth/logout, because the caller is now afetch()that would otherwise replay the POST against logout; both dialogs share a newdeleteAuth0Identity()helper and drive the logout navigation themselves, so a failed Auth0 deletion surfaces as an error toast instead of rendering a raw JSON 500 at the user.Blast radius of the original bug was bounded — only the Auth0 leg is deleted, the Hasura row survives (it is removed by a separate client-side mutation the attacker cannot reach) and
login-callbackre-links World ID / email-OTP users on next login, so permanent loss was confined to password-connection users plus everyone's MFA/passkey enrollments anduser_metadata.Verified against a running dev server, not just tests:
GET+Sec-Fetch-Site: cross-site(the exploit)POST+Sec-Fetch-Site: cross-sitecross_origin_requestPOST+Origin: https://evil.examplePOSTwith no origin metadataPOST+Sec-Fetch-Site: same-originPOST+Origin: <APP_BASE_URL>Not addressed here, flagged rather than silently scoped in: the client deletes the Hasura row before the Auth0 identity, so a failure of the second call still leaves a partial state — this PR makes that failure visible (error toast) rather than making the pair atomic — and no step-up re-authentication was added, since that is a product decision and not required to close the CSRF.
Checklist
🤖 Generated with Claude Code