Skip to content

security: add auth gates to 4 unprotected API routes - #2

Open
isaJrKai wants to merge 1 commit into
mainfrom
fix/auth-gate-api-routes
Open

security: add auth gates to 4 unprotected API routes#2
isaJrKai wants to merge 1 commit into
mainfrom
fix/auth-gate-api-routes

Conversation

@isaJrKai

Copy link
Copy Markdown
Owner

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

Route Method Issue
/api/achievements GET Revoked session could read
/api/lessons GET Revoked session could read
/api/lessons/complete POST Revoked session could submit quizzes
/api/recommendations GET Revoked session could read

The fix

Each handler now starts with:

const user = await getAuthUser();
if (!user) return NextResponse.json({ error: "Authentication required" }, { status: 401 });

getAuthUser() verifies BOTH the JWT signature AND that the Session row is active.

Files changed (4 files)

  • src/app/api/achievements/route.ts
  • src/app/api/lessons/route.ts
  • src/app/api/lessons/complete/route.ts
  • src/app/api/recommendations/route.ts

Verification

  • npx tsc --noEmit — clean
  • npx eslint — clean

Vercel env vars

None needed.

Deployment risk

Zero downtime. Only revoked/expired sessions get 401 instead of 200.

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.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@isaJrKai, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fbb44cbb-7238-4d52-9cfd-b5c064f58287

📥 Commits

Reviewing files that changed from the base of the PR and between 7053878 and aa198bb.

📒 Files selected for processing (4)
  • src/app/api/achievements/route.ts
  • src/app/api/lessons/complete/route.ts
  • src/app/api/lessons/route.ts
  • src/app/api/recommendations/route.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/auth-gate-api-routes

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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