Skip to content

[Bug]: auth: sign-out answers 200 and clears the cookie when deleting the session fails, leaving the session valid #980

Closed

Description

@jimhoyd

Security-sensitive (a session survives a sign-out the user saw succeed), severity: low. Found in an adversarial review of the auth 503 handling (#934, #968). The storage fault was simulated.

Runtime revision and environment

origin/main ba9f3204 (better-auth 1.7.6 from the lockfile), Node 26.10, macOS.

What happens

The auth mount turns Better Auth's 5xx/throws into 503 auth_unavailable and passes through anything below 500 (packages/auth/src/auth.ts handle, around line 237). Better Auth's /sign-out catches a deleteSession failure itself, logs it, and still answers 200 {"success":true} with cookie-clearing Set-Cookie. So when the session delete hits a storage error, the client is told it signed out, but the session row survives. Any copy of the token taken before sign-out (another tab or device, a captured cookie) stays valid until it expires. The documented "storage failure → 503" contract does not hold for sign-out.

Minimal reproduction

Sign in; CREATE TRIGGER fail_delete BEFORE DELETE ON session BEGIN SELECT RAISE(ABORT, 'simulated disk I/O error'); END on auth.sqlite; POST /api/auth/sign-out with the session cookie and a same-origin Origin; drop the trigger; send GET to an auth: true route with the old cookie.

sign-out 200 {"success":true} set-cookie: ['better-auth.session_token=; Max-Age=0; …', …]
/me with the "signed-out" cookie after storage recovers: 200 {"identity":{"userId":"…"}}

Observed with the simulated fault. Not verified: how often a real lock or full disk fails on the delete rather than on the rate-limit write that comes before it, which would already answer 503.

Suggested fix

For /sign-out (and /revoke-session(s)), have the mount confirm the session is gone before passing a success through, and answer 503 otherwise. Or raise the swallowed error upstream with Better Auth and document the gap meanwhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions