Skip to content

Auth/PM-38742 - SSO Invited Existing User Flow Improvement - Redirect on error #7785

Open
JaredSnider-Bitwarden wants to merge 7 commits into
mainfrom
auth/pm-38742/sso-callback-improve-error-for-invited-existing-users
Open

Auth/PM-38742 - SSO Invited Existing User Flow Improvement - Redirect on error #7785
JaredSnider-Bitwarden wants to merge 7 commits into
mainfrom
auth/pm-38742/sso-callback-improve-error-for-invited-existing-users

Conversation

@JaredSnider-Bitwarden

@JaredSnider-Bitwarden JaredSnider-Bitwarden commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-38742
Clients PR: bitwarden/clients#21134

📔 Objective

Redirect invited existing users back to /login on SSO callback

Replace the thrown exception at the invited-user gate with a typed SsoAuthnRequiresInviteAcceptanceException caught in ExternalCallback, which signs out the temp external cookie and redirects to the web vault's /login with the email, org name, and an error code. The web client renders a toast prompting the user to sign in with master password and accept the invite. Preserves the security gate — no SsoUser row is written and no auth session is established for invited users.

📸 Screenshots

See clients PR: bitwarden/clients#21134

…back

Replace the thrown exception at the invited-user gate with a typed
SsoAuthnRequiresInviteAcceptanceException caught in ExternalCallback, which
signs out the temp external cookie and redirects to the web vault's /login
with the email, org name, and an error code. The web client renders a toast
prompting the user to sign in with master password and accept the invite.
Preserves the Prevented Bypass 1 security gate — no SsoUser row is written
and no auth session is established for invited users.
@JaredSnider-Bitwarden JaredSnider-Bitwarden added the ai-review Request a Claude code review label Jun 8, 2026
@JaredSnider-Bitwarden JaredSnider-Bitwarden changed the title Auth/PM-38742 - Redirect invited existing users back to /login on SSO call… Auth/PM-38742 - SSO callback for invited, existing users Redirect invited existing users back to /login on SSO call… Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed the SSO invited-existing-user flow change in the SSO AccountController. The invited-status gate now throws a typed SsoAuthnRequiresInviteAcceptanceException caught in ExternalCallback, which signs out the external cookie and redirects to the web vault /login with URL-encoded context. Verified the security invariant is preserved (no SsoUser row written, no auth session established for invited users) and that the redirect base is a server-controlled constant with all user-influenced values URL-encoded. Confirmed the removed AcceptInviteBeforeUsingSSO resource string has no remaining references.

Code Review Details

No findings.

The change is well-scoped and thoroughly tested across unit, integration, and exception-level tests. The cookie-cleanup mirrors the success path, the email carried in the redirect comes from the canonical non-nullable User.Email, and Uri.EscapeDataString guards against query-string injection from the org display name and email.

@JaredSnider-Bitwarden JaredSnider-Bitwarden changed the title Auth/PM-38742 - SSO callback for invited, existing users Redirect invited existing users back to /login on SSO call… Auth/PM-38742 - SSO Invited Existing User Flow Improvement - Redirect on error Jun 8, 2026
The existing integration test for an existing user with an invited org user
was asserting the prior 500-error behavior. With the redirect change in
6a9e708, the endpoint now returns 302 to the web vault /login carrying the
email, org name, and error code. Rename the test and update assertions to
verify the redirect status, the Location path, the error query param, and
that the seeded user's email + organization display name flow through into
the URL (which the unit test cannot exercise because it has no real DB
roundtrip).
@JaredSnider-Bitwarden JaredSnider-Bitwarden marked this pull request as ready for review June 8, 2026 21:10
@JaredSnider-Bitwarden JaredSnider-Bitwarden requested a review from a team as a code owner June 8, 2026 21:10
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.23%. Comparing base (3c0b1ec) to head (0515824).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7785      +/-   ##
==========================================
- Coverage   61.27%   61.23%   -0.04%     
==========================================
  Files        2194     2211      +17     
  Lines       97468    97747     +279     
  Branches     8792     8815      +23     
==========================================
+ Hits        59722    59855     +133     
- Misses      35625    35768     +143     
- Partials     2121     2124       +3     

☔ View full report in Codecov by Harness.
📢 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.

JaredSnider-Bitwarden and others added 2 commits June 9, 2026 11:34
Extend SsoRedirectUrlBuilder with an optional autoSubmit boolean that
appends &autoSubmit=true when set; pass autoSubmit: true from the catch
site so the client can skip the email-entry step and land directly on
master-password entry. Also remove the now-orphaned AcceptInviteBeforeUsingSSO
resx string — no C# code references it after the previous commit moved
the message to the client side.
Comment thread bitwarden_license/src/Sso/Utilities/SsoRedirectUrlBuilder.cs Outdated
Comment thread bitwarden_license/src/Sso/Utilities/SsoRedirectUrlBuilder.cs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The forethought is clear for how this can be expanded in the future with the sso redirect url builder. What I thought would be errors in docs turned out to be incorrect. Tests look great too, no notes!

@JaredSnider-Bitwarden JaredSnider-Bitwarden removed the request for review from rr-bw June 9, 2026 20:18
JaredSnider-Bitwarden and others added 3 commits June 10, 2026 13:15
…bmit

Extend SsoAuthnRequiresInviteAcceptanceException with the org id and emit
it as &organizationId={guid} in the BuildLoginRedirectUrl output so the
web client can match the redirect against its stashed invite by a stable
key (display names can drift between invite send-time and SSO attempt).
Drop the autoSubmit parameter — the client now derives auto-progression
from its own stash state, so the server-side hint is redundant.
@sonarqubecloud

Copy link
Copy Markdown

@JaredSnider-Bitwarden

Copy link
Copy Markdown
Contributor Author

Recent changes are to fix bug: https://bitwarden.atlassian.net/browse/PM-39149

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants