Skip to content

fix: return 400 for an expired or reused OAuth connect state - #2050

Open
giladresisi wants to merge 1 commit into
stagingfrom
fix/social-connect-invalid-state-4xx
Open

giladresisi wants to merge 1 commit into
stagingfrom
fix/social-connect-invalid-state-4xx

Conversation

@giladresisi

Copy link
Copy Markdown
Collaborator

What kind of change does this PR introduce?

Bug fix (backend OAuth callback + frontend connect page). In NoAuthIntegrationsController.connectSocialMedia, the bare throw new Error('Invalid state') / 'Organization not found' for a missing Redis state key are now a 400 HttpException with the message "This connection link has expired or was already used, please start the connection again". In continue.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 state is the third most frequent backend error in production: 99 events in the last 24h and 542 in the last 7 days on POST /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

  1. With a valid timezone in the body, POST /integrations/social-connect/reddit with {"state":"does-not-exist","code":"x","timezone":"0"} and expect a 400 whose message is the new text (was a 500)
  2. Logged in, click Add Channel, pick Reddit, and copy the state query param from the Reddit consent URL without clicking Allow
  3. Open http://localhost:4200/integrations/social/reddit?state=<state>&code=fake-code once; it consumes the state and shows "Authentication failed" (unchanged behaviour)
  4. Reload the same URL; the network tab shows a 400 and the page shows "Could not add provider." with the new message underneath instead of a repeated "Could not add provider"
  5. Complete a real connect for any OAuth provider and confirm it still succeeds

Checklist:

  • I have read the CONTRIBUTING guide.
  • I have signed the Contributor License Agreement (CLA) (ICLA for individuals, CCLA for entities).
  • I confirm I have not used AI to submit this PR or generate code for it.
  • I checked that there were no similar issues or PRs already open for this.
  • This PR fixes just ONE issue
  • I have filled in the QA section above with real steps to verify this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_017g3KqiuR5TT68XdqpTRbZh

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
@postiz-contribution postiz-contribution Bot added the contribution:approved Approved contributor label Sep 9, 2026
@strix-security

strix-security Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Strix Security Review

No security issues found.

Updated for 915657d.


Reviewed by Strix
Re-run review · Configure security review settings

@postiz-agent

postiz-agent Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution:approved Approved contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant