Repository navigation
fix(local): revoke the grant a ChatGPT sign-in replaces - #2174
Conversation
|
@Cedric921 is attempting to deploy a commit to the Rohan Verma'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 configuration
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughRepeat sign-in captures tokens from an existing ChatGPT connection. When the new grant uses a different client and revocation is permitted, the flow revokes the old tokens after it saves the new tokens and marks the flow ChangesChatGPT repeat sign-in
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to No identified issue remains that should block merging the repeat sign-in change. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Saving the new sign-in before revoking an eligible old grant is a sound improvement. No introduced security regression was established, but cleanup remains best effort, same-client tokens are deliberately retained, and deployed configuration and real-provider behavior remain unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
…-revoke-on-sign-in-again # Conflicts: # docs/architecture/chatgpt-subscription.md
|
Reviewed this. The shape matches sign-out and delete:
Two things before it can merge. 1. Since #2192, the token this revokes belongs to the same client as the new sign-inWhen this was written, the authorize URL always registered a new dynamic client, so the replaced token belonged to a different client. On
So every revocation this PR makes now targets the same user, client and resource as the session it just created. RFC 7009 §2.1 lets a server revoke the whole grant when one refresh token is revoked, and Auth0, for one, does exactly that when its "Refresh Token Revocation Deletes Grant" setting is on. Nothing we have shows which way OpenAI goes. If it revokes the grant, signing in again shows "signed in", and then the next refresh gets What to change
2. The guards have no tests on the sign-in-again pathTwo changes that break it both pass all 20 tests in
What to changeAdd three tests:
Not blocking:
Push the fixes to this branch and it will be reviewed again. |
|
Both fixed, and both non-blocking points too, in the latest push.
|
|
Merged into
|
What
Signing in again on a ChatGPT connection that is still signed in now revokes the refresh token it replaces, the same way sign-out and delete do since #2156.
flows._savereads the connection's current tokens throughrevocation.tokens_to_revokebeforesave_sign_inoverwrites them, then commits.revocation.revoke, so the new sign-in stands whatever OpenAI answers.Why
docs/architecture/chatgpt-subscription.mdlisted it under Known gaps, a line #2156 added at review: Sign in again on a live connection overwrote its tokens without revoking the grant they replace, which left that grant open at OpenAI with nothing on this machine able to end it.Fixes
No issue. This closes that Known gaps line, which is deleted here. The URL table row and the revocation bullet now name signing in again.
How to test
cd surfsense_local/backend uv run pytest tests/integration/llm/chatgpt tests/integration/llm/test_connections.py -q uv run ruff check modules/llm tests/integration/llm/chatgpt python ../../scripts/check_docs.pyTwo new tests in
test_sign_in_routes.py:56 passed.
High-level PR Summary
This PR fixes a security gap where signing in again on an existing ChatGPT connection would overwrite tokens without revoking the replaced OAuth grant at OpenAI. The fix ensures that when a user signs in again over a live connection, the old refresh token is revoked at OpenAI (similar to how sign-out and delete already work), preventing orphaned grants that couldn't be terminated. The implementation reads tokens before overwriting them, commits the new sign-in, then revokes the old tokens as a best-effort operation.
⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
docs/architecture/chatgpt-subscription.mdsurfsense_local/backend/tests/integration/llm/chatgpt/test_sign_in_routes.pysurfsense_local/backend/modules/llm/subscriptions/chatgpt/flows.pySummary by CodeRabbit