fix: redirect to login page on manual admin/logout call in the browser#3564
fix: redirect to login page on manual admin/logout call in the browser#3564crivetimihai merged 2 commits intomainfrom
Conversation
PR Review Report — PR #3564: Redirect manually accessed admin/logout to admin/login pageAuthor: @marekdano Branch: SummaryThis PR addresses issue #3555 by implementing logic to redirect browser users who manually navigate to Changes: 2 files modified (1 source file, 1 test file) Linked Issues — Completion Status
Overall Issue Coverage: Primary requirement addressed. However, see security findings below regarding cookie clearing for OIDC callbacks. Security FindingsOverviewNo critical security vulnerabilities identified. One medium-severity functional issue found related to OIDC front-channel logout cookie handling. The implementation correctly distinguishes between browser requests and OIDC callbacks, but may not fully comply with OIDC front-channel logout specification regarding session clearing. Findings Summary
Suggestions
Invariant ComplianceAll ContextForge security invariants satisfied. The implementation maintains proper authentication flow and doesn't introduce privilege escalation risks. Deny-Path CoverageNo security-sensitive changes requiring deny-path regression tests identified. General PR Quality
Files Changed
Code Review Findings5 issues identified (1 medium, 4 low severity) - All added to Bob Findings panel:
Overall Verdict
Recommendation: The PR successfully addresses the reported issue (#3555) by redirecting browser users from Recommended Actions:
|
msureshkumar88
left a comment
There was a problem hiding this comment.
✅ PR #3564 Review Update — All Recommended Changes Implemented
Reviewed by: @msureshkumar88
Status: All 4 recommended actions have been successfully implemented
Changes Verification Summary
✅ 1. Cookie Clearing for All Logout Types (Medium Priority)
Status: IMPLEMENTED
The cookie clearing logic (lines 4297-4308) is now outside the if/else block, ensuring that session cookies are cleared for all logout scenarios including:
- POST requests (user-initiated)
- GET requests with browser headers (manual navigation)
- GET requests without browser headers (OIDC front-channel callbacks)
This fixes the medium-severity issue where OIDC front-channel logout callbacks were not properly clearing session cookies.
✅ 2. Browser Detection Aligned with Middleware Patterns
Status: IMPLEMENTED
The browser detection logic (lines 4269-4275) now matches the patterns used in auth_middleware.py:188 and rbac.py:264:
accept_header = request.headers.get("accept", "")
is_htmx = request.headers.get("hx-request") == "true"
referer = request.headers.get("referer", "")
is_browser_request = "text/html" in accept_header or is_htmx or "/admin" in referer
This ensures consistent behavior across the codebase for detecting browser vs API requests.
✅ 3. Docstring Updated for Three Logout Scenarios
Status: IMPLEMENTED
The function docstring (lines 4117-4125) now clearly documents all three logout scenarios:
- POST: User-initiated logout from UI
- GET with browser headers: Browser navigation to /admin/logout
- GET without browser headers: OIDC front-channel logout callback
The docstring also includes a reference to the OpenID Connect Front-Channel Logout 1.0 specification.
✅ 4. Edge Case Test Coverage Added
Status: IMPLEMENTED
Comprehensive test coverage has been added (lines 499-523) for edge cases:
- ✅ HX-Request header detection (HTMX requests)
- ✅ Admin referer detection
- ✅ Wildcard Accept header (
*/*) - ✅ Multiple Accept types (
text/html,application/xhtml+xml)
Additional Improvements Implemented
Beyond the recommended changes, the following enhancements were also made:
-
OIDC Spec Reference Added (lines 4281-4284)
- Added explicit reference to OpenID Connect Front-Channel Logout 1.0 spec
- Includes URL: https://openid.net/specs/openid-connect-frontchannel-1_0.html
-
Improved Code Comments (lines 4269-4271)
- Added comment explaining the need for consistency with auth_middleware.py and rbac.py
- Clarified the distinction between browser navigation and OIDC callbacks
Final Verdict
| Dimension | Previous Rating | Current Rating |
|---|---|---|
| Issue Completion | 🟢 Complete | 🟢 Complete |
| Security Risk | 🟡 Medium | 🟢 Low |
| PR Quality | 🟡 Needs Work | 🟢 Good |
Updated Recommendation: ✅ APPROVE
All identified issues have been resolved:
- ✅ Cookie clearing now works for all logout types (including OIDC callbacks)
- ✅ Browser detection is consistent with existing middleware patterns
- ✅ Documentation is complete and accurate
- ✅ Comprehensive test coverage for edge cases
The PR is now ready for merge. The implementation correctly addresses issue #3555 while maintaining OIDC front-channel logout compliance and ensuring consistent behavior across the authentication system.
078f8af to
7d17766
Compare
crivetimihai
left a comment
There was a problem hiding this comment.
Rebased onto main (clean, no conflicts) and reviewed.
Design & Logic — Sound. The fix correctly distinguishes three logout scenarios:
- Browser GET (Accept: text/html / HX-Request / admin Referer) → redirect to login (303)
- OIDC front-channel GET (no browser headers) → 200 OK per OpenID Connect Front-Channel Logout 1.0 spec
- POST (UI button) → redirect to login (or Keycloak RP-initiated logout)
Consistency — The browser detection pattern ("text/html" in accept_header or is_htmx or "/admin" in referer) exactly matches the established pattern in middleware/auth_middleware.py and middleware/rbac.py.
Security — No issues. Redirect target is hardcoded ({root_path}/admin/login), cookies are always cleared regardless of path, no open redirect or header injection vectors, */* accept header correctly falls through to OIDC path.
Test coverage — All new code paths are covered (6 test cases: POST redirect, browser GET redirect, OIDC GET 200, HTMX GET redirect, referer GET redirect, wildcard accept GET 200). All 59 admin tests pass.
Docs — SSO tutorial update accurately describes the three scenarios.
LGTM.
Signed-off-by: Marek Dano <Marek.Dano@ibm.com>
Signed-off-by: Marek Dano <Marek.Dano@ibm.com>
7d17766 to
9dead74
Compare
#3564) * fix: redirect to login page on manual admin/logout call in the browser Signed-off-by: Marek Dano <Marek.Dano@ibm.com> * fix: add to handle htmx header, add comments and update docs Signed-off-by: Marek Dano <Marek.Dano@ibm.com> --------- Signed-off-by: Marek Dano <Marek.Dano@ibm.com> Co-authored-by: Marek Dano <Marek.Dano@ibm.com>
#3564) * fix: redirect to login page on manual admin/logout call in the browser Signed-off-by: Marek Dano <Marek.Dano@ibm.com> * fix: add to handle htmx header, add comments and update docs Signed-off-by: Marek Dano <Marek.Dano@ibm.com> --------- Signed-off-by: Marek Dano <Marek.Dano@ibm.com> Co-authored-by: Marek Dano <Marek.Dano@ibm.com>
#3564) * fix: redirect to login page on manual admin/logout call in the browser Signed-off-by: Marek Dano <Marek.Dano@ibm.com> * fix: add to handle htmx header, add comments and update docs Signed-off-by: Marek Dano <Marek.Dano@ibm.com> --------- Signed-off-by: Marek Dano <Marek.Dano@ibm.com> Co-authored-by: Marek Dano <Marek.Dano@ibm.com>
Closes: #3555
🐛 Bug-fix PR
📌 Summary
Fixed admin logout behavior to redirect browser users to the login page while maintaining OIDC front-channel logout compliance.
Root causes
User Experience: Users manually navigating to /admin/logout in browser are now automatically redirected to login page
🔁 Reproduction Steps
💡 Fix Description
mcpgateway/admin.py_admin_logout()using the Accept headertests/unit/mcpgateway/test_admin_module.py🧪 Verification
make lintmake testmake coverage📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)