Skip to content

Dev - #251

Merged
vernu merged 2 commits into
mainfrom
dev
Aug 2, 2026
Merged

Dev#251
vernu merged 2 commits into
mainfrom
dev

Conversation

@vernu

@vernu vernu commented Aug 2, 2026

Copy link
Copy Markdown
Owner

No description provided.

vernu and others added 2 commits August 2, 2026 12:39
Every API-key-authenticated request ran bcrypt.compareSync, blocking the
event loop 60-100ms and capping each process at roughly 10-20 req/s. That
was the first hard ceiling for device traffic (heartbeats, status
callbacks, inbound SMS).

API keys are high-entropy random tokens, so slow hashing buys nothing:
bcrypt exists to protect low-entropy passwords from offline brute force.
verifyApiKey now resolves a key with a single indexed sha256 lookup.

Keys issued before this change have no sha256 stored, so they fall back
to the old masked lookup plus one async bcrypt.compare, then backfill
their own sha256 and use the fast path from then on. Nothing is
invalidated and no user action is required. bcrypt hashes are still
written for new keys so a revert keeps authenticating every key.

New keys are txb_ plus 32 base62 characters, replacing uuidv4. The
prefix makes a leaked key identifiable and allows registering a secret
scanning pattern later. The masked display shape is unchanged, which is
what keeps a revert working for keys issued mid-migration.

Both AuthGuard and OptionalAuthGuard are migrated; the latter had the
same compareSync call and no test file, so it gets one.

Rejecting non-string input also fixes a pre-existing 500: an object or
array from the apiKey query param previously reached .substring().

Passwords continue to use bcrypt.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
perf(auth): resolve API keys via indexed sha256 instead of bcrypt
@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
textbee Ready Ready Preview Aug 2, 2026 11:08am

Request Review

@vernu
vernu merged commit 829498f into main Aug 2, 2026
8 checks passed
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