security: fix timing enumeration, add security headers, validate req.body#265
Merged
hoiekim merged 1 commit intohoiekim:mainfrom Mar 25, 2026
Merged
Conversation
Contributor
Author
Self-ReviewDiscussion thread status:
Checked:
E2E Testing:
Issues found:
Confidence: High |
Contributor
Author
Self-ReviewDiscussion thread status:
Checked:
E2E Testing:
Issues found:
Confidence: High |
…body - Fix timing-based username enumeration in login route by always running bcrypt.compare even when user is not found (Closes hoiekim#261) - Add X-Content-Type-Options, X-Frame-Options, Referrer-Policy, and HSTS (production only) security headers middleware (Closes hoiekim#262) - Add body shape validation to post-login.ts and post-set-info.ts to return clear 400 errors for invalid input types (Closes hoiekim#263)
7aedf2a to
6b7c960
Compare
hoiekim
approved these changes
Mar 25, 2026
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
Three security/quality fixes bundled together (all single-file or small scope).
Closes #261 — Timing-based username enumeration in login
Always run
bcrypt.compareeven when the user is not found, using a pre-computed dummy hash. This makes the response time indistinguishable whether or not the username exists. Same pattern used in budget PR (hoiekim/budget#136).Closes #262 — HTTP security headers
Added middleware in
src/server/lib/http/index.ts:X-Content-Type-Options: nosniffX-Frame-Options: DENYReferrer-Policy: strict-origin-when-cross-originStrict-Transport-Security(production only)Closes #263 — req.body shape validation in login and set-info routes
Both routes now validate the body is an object and required fields are strings before processing. Returns clear error messages instead of opaque 500s.
Testing
bun run tsc --noEmitpasses cleanly.