Skip to content

Conversation

AndrewHaZG
Copy link

Description

Fixes #11078

This PR extends the logout function to improve cookie cleanup by removing cookies for multiple paths and domains to ensure complete session termination.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

Improve cookie cleanup during logout by removing cookies across
multiple paths and domains to ensure complete session termination.

Fixes apache#11078
@DaanHoogland DaanHoogland requested review from Copilot and DaanHoogland and removed request for Copilot July 31, 2025 12:38
@DaanHoogland
Copy link
Contributor

@blueorangutan ui

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the logout function's cookie cleanup mechanism to ensure complete session termination by removing cookies across multiple paths and domains. The change addresses session issues that could occur when cookies are not properly cleaned up during logout.

  • Replaces simple cookie removal with comprehensive cleanup across multiple paths and domains
  • Adds logic to handle cookies for root path, client path, and various domain configurations
  • Uses nested loops to systematically remove all cookies with different path/domain combinations

@@ -472,9 +472,17 @@ const user = {
}).catch(() => {
resolve()
}).finally(() => {
const paths = ['/', '/client']
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting the hardcoded paths array to a configuration constant or module-level variable to improve maintainability and make it easier to modify these paths in the future.

Suggested change
const paths = ['/', '/client']
const paths = COOKIE_PATHS

Copilot uses AI. Check for mistakes.

@@ -472,9 +472,17 @@ const user = {
}).catch(() => {
resolve()
}).finally(() => {
const paths = ['/', '/client']
const hostname = window.location.hostname
const domains = [undefined, hostname, `.${hostname}`]
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The domains array construction could be simplified and made more readable by extracting the dot-prefixed hostname to a separate variable, e.g., const dotHostname = '.${hostname}' and then using [undefined, hostname, dotHostname].

Suggested change
const domains = [undefined, hostname, `.${hostname}`]
const dotHostname = `.${hostname}`
const domains = [undefined, hostname, dotHostname]

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm, I wonder why this would be only needed for saml2 logout and not for ldap or local? need testing.

Copy link

codecov bot commented Jul 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 16.16%. Comparing base (6589235) to head (6460a2e).
⚠️ Report is 18 commits behind head on 4.20.

Additional details and impacted files
@@            Coverage Diff            @@
##               4.20   #11361   +/-   ##
=========================================
  Coverage     16.15%   16.16%           
- Complexity    13277    13281    +4     
=========================================
  Files          5656     5656           
  Lines        497912   497948   +36     
  Branches      60383    60388    +5     
=========================================
+ Hits          80462    80490   +28     
- Misses       408494   408496    +2     
- Partials       8956     8962    +6     
Flag Coverage Δ
uitests 4.00% <ø> (-0.01%) ⬇️
unittests 17.01% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kiranchavala
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@kiranchavala a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 14549

Copy link
Collaborator

@rosi-shapeblue rosi-shapeblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - tested and verified without and with the fix (tested regular and SAML auth)

Test Results Overview:

  • Regular Auth Logout: Fixed from 9+ error requests to 4 clean requests
  • SAML Auth Logout: Fixed from API flooding (thousands of requests) to 4 clean requests
  • Cookie Cleanup - Regular: Fixed from partial/incomplete removal to complete cleanup
  • Cookie Cleanup - SAML: Fixed from mixed paths remaining to all paths cleaned
  • Authorization Errors: Fixed from 401 Unauthorized errors to no errors
  • User Experience: Fixed from error notifications to clean logout flow

SAML Testing Setup Process

Since the original issue was SAML-specific, MockSAML.com was used - a free online SAML 2.0 Identity Provider designed for testing SAML SSO integrations.

  1. Accessed MockSAML.com

  2. Configured CloudStack Global Settings:

saml2.enabled = true
saml2.sp.id = org.apache.cloudstack
saml2.idp.metadata.url = https://mocksaml.com/api/saml/metadata
saml2.redirect.url = http://10.0.35.20:8080/client/
saml2.default.idpid = https://saml.example.com/entityid
saml2.user.attribute = email
saml2.user.sessionkey.path = /
  1. Created SAML Test User via CloudMonkey:
bashcreate user [email protected] [email protected] 
firstname=Jackson lastname=Test password=temppass123 account=admin

authorizeSamlSso enable=true entityid=https://saml.example.com/entityid 
userid=b14581e4-dcbf-47a8-9b61-de94dc7d53f9
  1. Configured MockSAML Integration:
ACS URL: http://10.0.35.20:8080/client/api?command=samlSso
Test credentials: [email protected]

Detailed Test Results

Test Scenario 1: Regular Authentication (Control Test)

WITHOUT Fix

  • Network Requests: 9+ requests with multiple 401 errors
  • Cookie Cleanup: Incomplete - partial session state remains

WITH Fix

  • Network Requests: 4 clean requests, no errors
  • Cookie Cleanup: Complete removal of all session cookies
  • User Experience: Clean logout to login page

Test Scenario 2: SAML Authentication (Primary Test)

SAML Login State Analysis
Critical Cookie Configuration Observed:

isSAML = true (confirms SAML authentication)
Mixed Path Cookies:

sessionkey at path /
sessionkey at path /client...
JSESSIONID at path /client

Multiple Domain Variations: cookies across different domain formats
This exact state previously caused the API flooding bug

SAML Logout Test Results - WITH Fix

  • Network Requests: 4 clean requests (identical to regular auth)
  • Request Breakdown:
logout&sessionkey=... (200 OK)
listIdps (200 OK)
listOauthProvider (200 OK)
forgotPassword (401 - expected)

Test Results:

  • All SAML session cookies removed
  • Both / and /client path cookies cleaned
  • All domain variations cleared
  • Zero cookies remaining
Screenshot from 2025-08-13 11-47-33 Screenshot from 2025-08-13 11-49-09 Screenshot from 2025-08-13 11-48-47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI: Cannot log out / Invalid session cookies causes login page to flood API calls
6 participants