Skip to content

fix(backend): mount only the auth endpoints the game uses - #346

Merged
arrzdev merged 2 commits into
mainfrom
test/auth-standard-gaps
Nov 16, 2026
Merged

arrzdev merged 2 commits into
mainfrom
test/auth-standard-gaps

Conversation

@arrzdev

@arrzdev arrzdev commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

What and why

Adds three auth tests and the backend fix for the two that failed on main.

Fix: better-auth's catch-all is replaced with an allowlist in auth.routes.ts: sign-up/email, sign-in/email, sign-in/username, sign-out and get-session. Every other better-auth endpoint, /change-password and /is-username-available included, is now a 404. revokeSessionsOnPasswordReset: true is set for when a reset route is added. The route auth matrix test lists the new routes.

  • Password change leaves other sessions alive. better-auth's catch-all mounts /change-password. It only revokes other sessions when the client sends revokeOtherSessions: true. The test signs in on two devices, changes the password from one, and expects the other token to be refused. Today it still gets 200. Two fixes satisfy the test: force revocation on the server, or switch the endpoint off (404), since the game has no change-password screen.
  • /is-username-available reveals which usernames exist. It answers {"available":false} for a taken name without creating anything. The test expects the same status and body for a known and an unknown username.
  • Cookie flags. This pins HttpOnly and SameSite=Lax on the session cookie. It already passes.

How to verify

pnpm --filter @repo/backend exec vitest run src/http/routes/auth.routes.test.ts. On main: 2 failed, 28 passed. On this branch: 30 passed. Full backend suite: 620 passed.

UI quality gate

Not applicable: backend only.

…ookie flags

Two of these fail on main: /change-password leaves other sessions alive
unless the client asks, and /is-username-available tells anyone which
usernames exist.
better-auth's catch-all answered every endpoint it ships. Two of them
weakened auth: change-password kept other sessions alive unless the
client asked otherwise, and is-username-available told anyone which
usernames exist. The routes now allowlist sign-up, both password
sign-ins, sign-out and get-session; anything else is a 404.

Password resets also revoke every session, for when a reset route is
added.
@arrzdev arrzdev changed the title test(backend): auth standard gaps on password change and username probing fix(backend): mount only the auth endpoints the game uses Nov 16, 2026
@arrzdev
arrzdev marked this pull request as ready for review November 16, 2026 22:18

@arrzdev arrzdev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. The allowlist covers every endpoint the game client calls (sign-up/email, sign-in/username, sign-out, get-session) plus sign-in/email; everything else better-auth exposes is now 404, which closes both the change-password and username-probe gaps at the root. Rate-limit and origin middleware still run first. Tests pin the behaviour either way.

@arrzdev
arrzdev merged commit 533debb into main Nov 16, 2026
7 of 10 checks passed
@arrzdev
arrzdev deleted the test/auth-standard-gaps branch November 16, 2026 22:34
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