fix: return 400 for an expired or reused OAuth connect state - #2050
Open
giladresisi wants to merge 1 commit into
Open
giladresisi wants to merge 1 commit into
giladresisi wants to merge 1 commit into
Conversation
Was an unhandled 500 (99 events/24h in prod) and the frontend double-read the error body, hiding the message. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017g3KqiuR5TT68XdqpTRbZh
Strix Security ReviewNo security issues found. Updated for Reviewed by Strix |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
13 tasks
This branch has not been deployed
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.
What kind of change does this PR introduce?
Bug fix (backend OAuth callback + frontend connect page). In
NoAuthIntegrationsController.connectSocialMedia, the barethrow new Error('Invalid state')/'Organization not found'for a missing Redis state key are now a 400HttpExceptionwith the message "This connection link has expired or was already used, please start the connection again". Incontinue.integration.tsx, the 400 branch used to read the response body to decide whether to retry and the generic error branch then read it again, which failed on the consumed stream and always fell back to "Could not add provider"; the first parse is now kept and reused. The OAuth flow itself, the single-use deletion of the state key and the 1h TTL are unchanged.Why was this change needed?
Invalid stateis the third most frequent backend error in production: 99 events in the last 24h and 542 in the last 7 days onPOST /integrations/social-connect/:integration(Sentry CLOUD-EY), spread across 13 providers roughly in proportion to connect volume (YouTube 225, Instagram 90, Facebook 66 over 7d). The state key is deleted after its first use and expires after an hour, so a refreshed, re-opened or bookmarked callback URL legitimately has no key. That is an expected user-side condition, not a server fault, but it surfaced as an unhandled 500 that counts in Sentry and left the user with a dead-end "Could not add provider" screen with no hint to start over.Other information:
The frontend double read is likely the same mechanism as the "body stream already read" issues (CLOUD-RY, CLOUD-PG), not verified here.
QA
timezonein the body,POST /integrations/social-connect/redditwith{"state":"does-not-exist","code":"x","timezone":"0"}and expect a 400 whosemessageis the new text (was a 500)statequery param from the Reddit consent URL without clicking Allowhttp://localhost:4200/integrations/social/reddit?state=<state>&code=fake-codeonce; it consumes the state and shows "Authentication failed" (unchanged behaviour)Checklist:
🤖 Generated with Claude Code
https://claude.ai/code/session_017g3KqiuR5TT68XdqpTRbZh