HOTFIX: API key auth was broken -- AuthenticationError blocked fallback path#285
Conversation
|
@DevanshuNEU is attempting to deploy a commit to the Dev's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughModified JWT validation in the authentication middleware: Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Middleware as Auth Middleware
participant JWT as JWT Validator
participant APIKey as API Key Validator
participant App as Application
Client->>Middleware: Send request with auth header
Middleware->>JWT: Validate JWT
alt JWT valid
JWT-->>Middleware: Return user info
Middleware->>App: Forward authenticated request
else JWT invalid or AuthenticationError (now returns None)
JWT-->>Middleware: Return None
Middleware->>APIKey: Check API key
alt API key valid
APIKey-->>Middleware: Return API key identity
Middleware->>App: Forward authenticated request
else
APIKey-->>Middleware: Reject
Middleware-->>Client: Respond 401
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
… cause) _validate_jwt caught AuthenticationError and raised HTTPException 401 immediately, preventing _validate_api_key from ever running. ci_ API keys hit verify_jwt -> fail local decode -> fall back to Supabase API call -> also fails -> raises AuthenticationError. The middleware treated this as a hard failure instead of allowing the API key path to try next. Fix: catch AuthenticationError and return None (same as InvalidTokenError). Root cause of all MCP 401 errors since day one.
db69945 to
2a072c5
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Production bug -- MCP 401 on every request
One line in
middleware/auth.pywas blocking ALL API key authentication since day one.Root cause
When a
ci_API key hits_validate_jwt, it fails local JWT decode, then falls back to Supabase API verification, which also fails and raisesAuthenticationError. This was caught and immediately raised HTTP 401 -- the_validate_api_keyfunction never got a chance to run.Impact
Fix
1 file, 3 lines changed. Catch
AuthenticationErrorand returnNone(same asInvalidTokenError) to allow the API key fallback path.392 backend tests pass.
Summary by CodeRabbit