fix(consent): ignore ErrNoRows when revoking an already-deleted login session (closes #3504) - #4125
Conversation
… session revokeAuthenticationSession propagated sqlcon.ErrNoRows from DeleteLoginSession, so when a headless logout (by sid) had already deleted the session but the stale cookie still carried the sid, the next remember:false login 404'd. Ignore ErrNoRows there, using the same errors.Is(err, sqlcon.ErrNoRows()) idiom already used elsewhere in this file. Adds an e2e subtest driving a real login+consent flow whose sid has no DB row. Closes ory#3504 Signed-off-by: pacocartones <pacocartones@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughOAuth authorization now treats deletion of an already-missing login session as a successful no-op. A regression test verifies that authorization succeeds when the browser retains a stale authentication cookie. ChangesOAuth stale session handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change makes already-completed login-session revocation idempotent, allowing affected OAuth login flows to continue while preserving failures for other database errors and existing security checks. No actionable merge-blocking risk remains beyond normal checks. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description explains the bug, the fix, the affected flow, the related issue, and the regression test. The template checklist is not reproduced or completed, but the substantive information is complete.
✨ 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 |
Closes #3504.
The bug
revokeAuthenticationSession(consent/strategy_default.go) calledDeleteLoginSession(ctx, sid)and returned its error directly.Persister.DeleteLoginSessionreturnssqlcon.ErrNoRowswhen the row is already gone. So when a headless logout (revokeOAuth2LoginSessionsbysid) had already deleted the session but the stale cookie still carried thatsid, the nextremember:falselogin hit this path, gotErrNoRows, and the 404 killed the login — matching the reported stack trace.The fix
As @aeneasr specified in the issue: ignore
sqlcon.ErrNoRows()here (the session is already gone, which is acceptable). Uses the exacterrors.Is(err, sqlcon.ErrNoRows())idiom already used twice in this same file.Test
Adds a subtest to the existing
TestStrategyLoginConsentNextdriving a real/oauth2/authlogin+consent flow with a session cookie whosesidhas no DB row (the post-headless-logout state), asserting the flow still yields an authorization code.go test ./consent/passes; reverting only the fix makes the new test fail with the propagatedErrNoRowsnamingrevokeAuthenticationSession.Disclosure: this contribution was prepared with AI assistance (Claude Code); the fix, the code paths, and the test were verified against HEAD.
Summary by CodeRabbit