security: add auth gates to 4 unprotected API routes - #2
Conversation
Routes affected: - GET /api/achievements - GET /api/lessons - POST /api/lessons/complete - GET /api/recommendations These routes relied on middleware (JWT signature check) without verifying the server-side session was still active. A logged-out user with a cached JWT could still call them. Fix: add getAuthUser() check at top of each handler. Returns 401 if the JWT is invalid OR the session is revoked/expired.
|
Warning Review limit reached
More reviews will be available in 29 minutes and 45 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What this fixes
Adds
getAuthUser()checks to 4 API routes that relied on middleware alone (JWT signature check) without verifying the server-side session was still active.Vulnerable routes
/api/achievements/api/lessons/api/lessons/complete/api/recommendationsThe fix
Each handler now starts with:
getAuthUser()verifies BOTH the JWT signature AND that theSessionrow is active.Files changed (4 files)
src/app/api/achievements/route.tssrc/app/api/lessons/route.tssrc/app/api/lessons/complete/route.tssrc/app/api/recommendations/route.tsVerification
npx tsc --noEmit— cleannpx eslint— cleanVercel env vars
None needed.
Deployment risk
Zero downtime. Only revoked/expired sessions get 401 instead of 200.