fix: resolve JWT authentication bypass vulnerability (#1854) - #1865
fix: resolve JWT authentication bypass vulnerability (#1854)#1865atul-upadhyay-7 wants to merge 1 commit into
Conversation
|
@atul-upadhyay-7 is attempting to deploy a commit to the durdana3105's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
Next review available in: 46 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?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 reviews. How do review 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 refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAuthentication configuration and verification are hardened across local JWT, cron secret, and webhook secret flows. JWT algorithm and claim validation are expanded, while secret comparisons use timing-safe checks. ChangesAuthentication hardening
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/middlewares/requireAuth.js`:
- Around line 56-69: The claim validation logic must enforce the complete
Supabase access-token contract when local HMAC verification is enabled. Update
the JWT validation block around the existing exp/iat/iss/aud checks to require
integer exp and iat, issuer `${SUPABASE_URL.replace(/\/$/, "")}/auth/v1`, string
sub, and an aud value containing the configured user audience (defaulting to
“authenticated”); reject missing or invalid claims while preserving valid array
and string audience handling.
In `@backend/routers/cronRoutes.js`:
- Around line 11-16: Update all three constantTimeCompare definitions in
backend/middlewares/requireAuth.js, backend/routers/cronRoutes.js (lines 11-16),
and backend/routers/notificationRoutes.js (lines 9-14) to check bufA.length and
bufB.length after creating the buffers and before calling
crypto.timingSafeEqual; return false when the byte lengths differ.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a6f86029-501f-47cb-88d7-631ab72a296d
📒 Files selected for processing (5)
.env.examplebackend/config.jsbackend/middlewares/requireAuth.jsbackend/routers/cronRoutes.jsbackend/routers/notificationRoutes.js
- Enforce strict algorithm validation (reject 'none' algorithm, only accept HS256) - Add timing-safe signature comparison to prevent timing attacks - Validate JWT claims: exp, iat, iss, aud - Add SUPABASE_JWT_SECRET to env config and .env.example - Apply timing-safe comparison to cron and webhook secret verification - Defense-in-depth against crafted JWTs with elevated roles
ec879d8 to
fde81ac
Compare
Summary
This PR fixes the P1 JWT authentication bypass vulnerability described in issue #1854.
Changes
backend/middlewares/requireAuth.js
backend/routers/cronRoutes.js
backend/routers/notificationRoutes.js
backend/config.js
.env.example
Security Impact
Testing
Closes #1854
Summary by CodeRabbit
Security Improvements
Configuration