Repository navigation
Conversation
Member
|
Not overly concerned about the backup code hashing — stated rationale is weak. Exploitation of plaintext stored backup codes requires database access or exfiltration vector. If that is the case it's game over already. |
Member
|
Well, the rest of it was good 🤔 |
palmoni5
force-pushed
the
fix/backup-code-hardening
branch
from
October 25, 2026 17:18
520a8bc to
18aefa4
Compare
Author
|
Fair point on the hashing, I've dropped it. The branch is rebased onto current master and now only contains the rate limit on the backup code route, CSRF on both challenge POSTs, and the backup code generation fix (existing codes still work, nothing changes in storage). |
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.
Summary
Hardens the backup-code and TOTP challenge routes.
1. No rate limiting on
POST /login/2fa/backupprocessTotpLoginhas a per-uid lock (locks:totp:<uid>), a 2s delay on failure, and a 10s penalty when spammed.processBackuphad none of these, so backup codes could be brute-forced online with no throttling. This PR mirrors the TOTP behaviour usinglocks:backup:<uid>. The lock is cleared on success, on failure (after the 2s delay) and on exception, matching the TOTP path.2. No CSRF protection on the two challenge POSTs
POST /login/2fa/totpandPOST /login/2fa/backupran withoutapplyCSRF, while thePUT /login/2fa/backuproute already had it. The templates rendered a hidden field namedcsrf, but core's CSRF middleware only readscsrf_token/_csrf, so the token was never checked. Both routes now usehostMiddleware.applyCSRFand the templates sendcsrf_token.3. Backup code entropy
utils.generateUUID().replace('-', '')removes only the first dash, so codes were 10 hex characters (~40 bits). They are now generated withcrypto.randomBytes(6)(12 hex chars). Existing codes keep working unchanged.🤖 Generated with Claude Code