fix(auth,users): harden OAuth callback and user sync (4 issues) - #224
Open
Darkvader-ship-it wants to merge 1 commit into
Open
Conversation
- auth: replace JWT-in-URL with single-use handoff code + httpOnly cookie
* AuthService.createHandoffCode/consumeHandoffCode stores 5m TTL opaque code
* githubCallback now sets httpOnly access_token cookie and redirects with ?code=
* POST /auth/handoff and /auth/exchange exchange code for JWT (single-use)
- auth: jwt strategy validates user existence on every request
* JwtStrategy now injects UsersService and calls findOneRaw(sub)
* throws UnauthorizedException when user row no longer exists
* supports Bearer header and httpOnly cookie extraction
- users: sync User row on re-login to prevent staleness
* upsertFromGithub now updates username/displayName/avatarUrl/email from
fresh GitHub profile when GithubAccount already exists
* respects username/email uniqueness
- users: prevent username-recycling takeover
* upsertFromGithub never reuses a User by username when githubId is new
* always creates a fresh User; collision on username generates a unique
variant via generateUniqueUsername
- escrow: fix duplicate JSDoc that broke tsc parsing
|
@Darkvader-ship-it Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@Darkvader-ship-it is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Branch:
fix/auth-hardening-jwt-handoff-user-sync-takeoverCommit:
62762c1Status: Created, committed, and pushed to origin.
Fix #1 – JWT in redirect URL
(
src/auth/auth.controller.ts:36,src/auth/auth.service.ts:1)AuthService.createHandoffCode()generates a 32-byte hex code with a 5‑minute TTL, single-use viaconsumeHandoffCode()(prunes expired).githubCallbacknow:createHandoffCode(accessToken),httpOnly access_tokencookie (securein production,sameSite:lax,maxAge 7d,path:/),${frontendUrl}/auth/callback?code=${code}(notoken=in the URL).POST /auth/handoffand aliasPOST /auth/exchange(
src/auth/auth.controller.ts:59) — exchanges the code for{ accessToken }, throwingUnauthorizedExceptionif missing/expired.Fix #2 – JWT validate bypass
(
src/auth/strategies/jwt.strategy.ts:1)UsersService, addedcookieExtractor(checksreq.cookiesor manual cookie header) and usesfromExtractors([Bearer, cookieExtractor]).validate()is now async and checkspayload.sub, then awaitsusersService.findOneRaw(payload.sub)— throwsUnauthorizedException('User no longer exists')if deleted, preventing token use after account deletion.Fix #3 – Staleness
(
src/users/users.service.ts:53)GithubAccountpath, updates:account.login,User.username,displayName,avatarUrl,emailfrom fresh input,userRepo.save(),findOneRaw().Fix #4 – Username takeover
(
src/users/users.service.ts:105)findOne({ where: { username: input.login } })fallback.githubId, always creates a freshUser.generateUniqueUsername()(username,username-1, …); if an email collision occurs, setsemailtonull.Spec updates
(
src/users/users.service.spec.ts:93)username-linktest with a takeover-prevention test.All 13 tests pass (
default.bash:1).Extra
src/escrow/escrow.service.ts:582that broketscparsing.Verified
token=absent from redirect URLcode=presentnpx jest src/users/users.service.spec.ts→ 13 passedgit pushsucceededLet me know if you need this as a commit message, PR description, or converted to a different format (JSON, plain text, etc.).