Skip to content

Hash session passphrases with scrypt before DB storage#3

Draft
Copilot wants to merge 2 commits intofix/prodfrom
copilot/sub-pr-1-again
Draft

Hash session passphrases with scrypt before DB storage#3
Copilot wants to merge 2 commits intofix/prodfrom
copilot/sub-pr-1-again

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 10, 2026

Session passphrases were stored in plaintext, exposing all credentials in a DB breach. All passphrase comparisons used !==, vulnerable to timing attacks.

Changes

  • lib/auth.ts (new): Passphrase hashing and verification utilities

    • hashPassphrase: scrypt (N=65536, r=8, p=1) with a random 16-byte salt, returns salt:hash hex string
    • verifyPassphrase: constant-time comparison via crypto.timingSafeEqual, validates component lengths before comparing
  • app/api/sessions/route.ts: Hash passphrase before DB insert

  • Verification endpoints — swap !== for verifyPassphrase():

    • app/api/sessions/[id]/rounds/route.ts
    • app/api/sessions/[id]/rounds/[roundId]/end/route.ts
    • app/api/sessions/[id]/shocks/route.ts
// Before
await sql`INSERT INTO sessions (id, passphrase, ...) VALUES (${id}, ${passphrase}, ...)`;
if (session[0].passphrase !== passphrase) return 401;

// After
const passphraseHash = await hashPassphrase(passphrase);
await sql`INSERT INTO sessions (id, passphrase, ...) VALUES (${id}, ${passphraseHash}, ...)`;
if (!(await verifyPassphrase(passphrase, session[0].passphrase))) return 401;

Uses only Node.js built-in crypto — no new dependencies.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
live-game Error Error Mar 10, 2026 5:42am

Co-authored-by: ghostleek <44336310+ghostleek@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on sessions API, DB lib and UI fixes Hash session passphrases with scrypt before DB storage Mar 10, 2026
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.

2 participants