Skip to content

[PM-29885] Implement SSO cookie vending authentication flow#6522

Open
SaintPatrck wants to merge 3 commits intomainfrom
cookie-vending/p9-t9_cookie-interceptor
Open

[PM-29885] Implement SSO cookie vending authentication flow#6522
SaintPatrck wants to merge 3 commits intomainfrom
cookie-vending/p9-t9_cookie-interceptor

Conversation

@SaintPatrck
Copy link
Contributor

@SaintPatrck SaintPatrck commented Feb 11, 2026

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-29885

📔 Objective

Add cookie interceptor support for enterprise SSO configurations that require ELB session cookies. The interceptor manages the full cookie lifecycle for API requests behind a load balancer:

  • Preemptive bootstrap: Detects when cookies are needed but not yet available and triggers acquisition before making a doomed request
  • Cookie attachment: Attaches stored cookies to outgoing API requests via the Cookie header
  • Redirect detection: Catches HTTP 302 responses indicating expired/missing cookies and triggers re-acquisition via the identity provider
  • Connection safety: Properly closes OkHttp responses before throwing to prevent connection pool exhaustion

Key components:

  • CookieInterceptor — OkHttp interceptor for request/response cookie handling
  • NetworkCookieManager / NetworkCookieManagerImpl — Bootstrap detection and cookie storage bridge
  • CookieRedirectException — Signal exception to trigger cookie acquisition flow
  • CookieProvider — Interface bridging the network and app layers

@github-actions github-actions bot added app:password-manager Bitwarden Password Manager app context app:authenticator Bitwarden Authenticator app context labels Feb 11, 2026
@SaintPatrck SaintPatrck added the ai-review Request a Claude code review label Feb 11, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 11, 2026

Logo
Checkmarx One – Scan Summary & Details023a8e8f-bc8d-4efc-94d6-5f89e409aab1

New Issues (4)

Checkmarx found the following issues in this Pull Request

# Severity Issue Source File / Package Checkmarx Insight
1 MEDIUM HttpOnly_Cookie_Flag_Not_Set /app/src/test/kotlin/com/x8bit/bitwarden/data/platform/manager/util/CookieConfigurationDataExtensionsTest.kt: 45
detailsThe web application's `toNetworkCookieList should map multiple cookies correctly` method creates a cookie Cookie, at line 45 of /app/src/test/kot...
Attack Vector
2 MEDIUM HttpOnly_Cookie_Flag_Not_Set /app/src/test/kotlin/com/x8bit/bitwarden/data/platform/manager/util/CookieConfigurationDataExtensionsTest.kt: 46
detailsThe web application's `toNetworkCookieList should map multiple cookies correctly` method creates a cookie Cookie, at line 46 of /app/src/test/kot...
Attack Vector
3 MEDIUM HttpOnly_Cookie_Flag_Not_Set /app/src/test/kotlin/com/x8bit/bitwarden/data/platform/manager/util/CookieConfigurationDataExtensionsTest.kt: 62
detailsThe web application's `toNetworkCookie should map name and value correctly` method creates a cookie Cookie, at line 62 of /app/src/test/kotlin/co...
Attack Vector
4 MEDIUM HttpOnly_Cookie_Flag_Not_Set /app/src/test/kotlin/com/x8bit/bitwarden/data/platform/manager/util/CookieConfigurationDataExtensionsTest.kt: 31
detailsThe web application's `toNetworkCookieList should map single cookie correctly` method creates a cookie Cookie, at line 31 of /app/src/test/kotlin...
Attack Vector

@claude
Copy link
Contributor

claude bot commented Feb 11, 2026

Claude finished @SaintPatrck's task in 5m 56s —— View job


Code Review: PM-29885 SSO Cookie Vending Authentication Flow

  • Gather context and read all changed files
  • Review network layer changes (interceptor, exception, models, provider)
  • Review app layer changes (manager, extensions, DI modules)
  • Review test coverage
  • Post review findings

Review complete. Inline comments have been posted on the PR for specific findings. Overall the implementation follows Bitwarden's architectural patterns well — proper interface/impl separation, clean UDF integration via CookieProvider, and solid test coverage. The Checkmarx HttpOnly Cookie Flag Not Set warnings are false positives on test-only Cookie objects.

@SaintPatrck SaintPatrck marked this pull request as ready for review February 11, 2026 22:59
@SaintPatrck SaintPatrck requested review from a team and david-livefront as code owners February 11, 2026 22:59
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 92.64706% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.31%. Comparing base (4cdd0b8) to head (4307955).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...atform/manager/network/NetworkCookieManagerImpl.kt 84.61% 0 Missing and 4 partials ⚠️
...arden/network/exception/CookieRedirectException.kt 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6522      +/-   ##
==========================================
- Coverage   86.38%   86.31%   -0.07%     
==========================================
  Files         777      797      +20     
  Lines       56175    56629     +454     
  Branches     8170     8192      +22     
==========================================
+ Hits        48527    48882     +355     
- Misses       4804     4895      +91     
- Partials     2844     2852       +8     

☔ 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.

Add cookie interceptor that manages ELB session cookies for enterprise
SSO configurations. The interceptor attaches stored cookies to API
requests, preempts requests when cookie bootstrap is needed, and detects
HTTP 302 redirects to trigger cookie re-acquisition via an identity
provider.

Key components:
- CookieInterceptor for OkHttp request/response cookie handling
- NetworkCookieManager for bootstrap detection and cookie storage
- CookieRedirectException to signal cookie acquisition flow
- CookieProvider interface bridging network and app layers

Co-Authored-By: Claude <noreply@anthropic.com>
@SaintPatrck SaintPatrck force-pushed the cookie-vending/p9-t9_cookie-interceptor branch from 5087f55 to 0dc2bc5 Compare February 12, 2026 01:03
This commit updates the `RetrofitsTest` to ensure that the `CookieInterceptor` is consistently called across all Retrofit client configurations.

Previously, the tests for `api`, `identity`, `events`, and `notifications` clients did not verify the presence of the cookie interceptor. This change adds an assertion (`assertTrue(isCookieInterceptorCalled)`) to each relevant test case to confirm that the interceptor is included in the chain.
// Return the response if it is not a redirect or does not contain
// a Location header.
val location = response.header(HEADER_LOCATION)
if (response.code != HTTP_REDIRECT || location == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be an &&?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm. Now that I think about it, we shouldn't need this location check. We should technically already have the IdP login URL saved. Could have swore I saw that in the spec somewhere. 🤔

Let me double check with the other teams and make sure we actually need to check and capture this.

Thanks for calling attention to this.

baseUrlsProvider = bitwardenServiceClientConfig.baseUrlsProvider,
),
cookieInterceptor = CookieInterceptor(
cookieProvider = bitwardenServiceClientConfig.cookieProvider,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor but can you just reference the cookieProvider property from above

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

Labels

ai-review Request a Claude code review app:authenticator Bitwarden Authenticator app context app:password-manager Bitwarden Password Manager app context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants