[PM-20012] fix: Incorrect endpoint saved - #2796
Conversation
🤖 Bitwarden Claude Code ReviewOverall Assessment: REQUEST CHANGES Reviewed the revised fix for PM-20012. The earlier approach (removing Code Review Details
|
| urls = .defaultUS | ||
| } | ||
|
|
||
| await setPreAuthURLs(urls: managedSettingsURLs ?? urls) |
There was a problem hiding this comment.
🤔 Are there any downsides to removing this? I think this currently is used so that the pre-auth URLs are updated when you switch the active account (the environment URLs when adding a new account are always set to the last active account). Assuming that's still a requirement, we should account for that before removing this.
There was a problem hiding this comment.
You may be right, I didn't test that flow. I'll test that, meanwhile this PR will be in draft. Thank you for bringing this to my attention.
# Conflicts: # BitwardenShared/Core/Platform/Services/EnvironmentServiceTests.swift
…when using autofill to login
| // Create the account. Prefer the environment URLs snapshotted for this email when the | ||
| // login flow started, since the global pre-auth URLs may have since been overwritten | ||
| // by an unrelated active-account sync (e.g. triggered by the AutoFill extension). | ||
| let urls: EnvironmentURLData? = if let accountCreationURLs = await stateService | ||
| .getAccountCreationEnvironmentURLs(email: email) { | ||
| accountCreationURLs | ||
| } else { | ||
| await stateService.getPreAuthEnvironmentURLs() | ||
| } |
There was a problem hiding this comment.
Details and fix
accountCreationEnvironmentURLs is only written in two places (LandingProcessor.validateEmailAndContinue and StartRegistrationProcessor on the email-verification path) and is never cleared, but it is now consulted for every login, so a leftover entry takes precedence over the current pre-auth URLs.
Traceable path:
- Landing on the US region, enter
email@x.com, tap Continue → snapshot = US. - Back out, switch the region to self-hosted server
S, tap Create account, register the same email. WhenstartRegistrationreturns a token directly (email verification disabled — common on self-hosted),StartRegistrationProcessornavigates to.completeRegistrationwithout updating the snapshot. CompleteRegistrationProcessor.setRegion()early-returns becausestate.fromEmail == false, so the pre-auth URLs are correctlySand the account is created onS. It then callsloginWithMasterPassword(username:isNewAccount: true), which reaches this code.- The snapshot still holds US → the account is persisted with US URLs while it actually lives on
S, which is the failure mode this PR is trying to prevent.
CompleteRegistrationProcessor:283 is a second route to .login(username:) that bypasses Landing, so it has the same exposure.
Suggested hardening: write the snapshot on every entry into the login/account-creation flow (including the direct-token path in StartRegistrationProcessor and the fallback navigation in CompleteRegistrationProcessor), and clear the entry once it has been consumed here so it can never be reused by a later flow.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2796 +/- ##
==========================================
+ Coverage 79.43% 81.72% +2.29%
==========================================
Files 1172 1049 -123
Lines 74915 67628 -7287
==========================================
- Hits 59506 55271 -4235
+ Misses 15409 12357 -3052 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🎟️ Tracking
PM-20012
📔 Objective
We are setting the pre-auth environment URLs when using the autofill. That data is shared with the main app, so if we use the autofill in middle of performing login we will have the wrong environment URLs for the account.