[iOS] NativeLoginManager Basic-Auth header uses URL-safe Base64 instead of standard Base64, breaking login for some username/password combinations - #4160
Closed
JohnsonEricAtSalesforce wants to merge 1 commit into
Conversation
generateColonConcatenatedBase64String() encoded the username:password credentials with the URL-safe alphabet and no padding, but RFC 7617 HTTP Basic Authentication requires the standard alphabet with padding. For most credentials the two alphabets produce identical output, but they diverge whenever the encoded bytes would contain +, /, or trailing = padding under the standard alphabet, silently breaking login for the affected accounts. Same defect class as the closed Android bug W-23986240 (fixed by dropping the URL_SAFE/NO_PADDING flags); the iOS Swift implementation independently had the identical bug and the fix was never ported over. Add regression tests covering both call sites that share this helper (login and the OTP/passwordless authorization flow) using a credential pair chosen to diverge between the two alphabets.
|
||||||||||||||||||
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #4160 +/- ##
==========================================
- Coverage 71.47% 67.57% -3.91%
==========================================
Files 254 254
Lines 22868 22900 +32
==========================================
- Hits 16346 15474 -872
- Misses 6522 7426 +904
🚀 New features to boost your workflow:
|
|
||||||||||||||
Contributor
Author
|
Superseded by #4161 (recreated from a correctly-named branch). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NativeLoginManagerInternal's helper for building the Basic-AuthAuthorizationheader (generateColonConcatenatedBase64String()) encoded the colon-concatenated username and password with the URL-safe Base64 alphabet and no padding (viaurlSafeBase64Encode()). HTTP Basic Authentication (RFC 7617) requires the standard Base64 alphabet with padding. For most credential pairs the two alphabets produce identical output, which is why this went unnoticed — they only diverge when the encoded bytes would contain+,/, or need=padding under the standard alphabet. When that happens, login fails with a generic "check your username and password" error even though the credentials are correct (confirmed working via web login for the same user).Same defect class as the already-fixed, closed Android bug W-23986240 — the iOS Swift implementation independently had the identical bug in its own encoding helper, and the Android fix was never ported to iOS.
generateColonConcatenatedBase64String()to encode with the standard Base64 alphabet (plaindata.base64EncodedString()) instead ofurlSafeBase64Encode().login(),submitAuthorizationRequest()(used by the OTP/registration-completion flows), andsubmitPasswordlessAuthorizationRequest()(OTP/passwordless login), so all three call sites are fixed by the one change.Scope note
This does not touch
urlSafeBase64Encode()'s other callers in the same file —generateCodeVerifier()andgenerateChallenge()— which correctly need URL-safe Base64 per RFC 7636 for PKCEcodeVerifier/codeChallengevalues and are unrelated to this HTTP Basic-Auth header.Test plan
login(), using a username/password pair whose combined UTF-8 bytes diverge between the standard and URL-safe alphabets (contains/and requires=padding under the standard alphabet); asserts theAuthorizationheader matches standard Base64 output.submitPasswordlessAuthorizationRequest()(a call site sharing the same helper), same divergent credential pair.NativeLoginManagerTestson the iOS simulator — both new tests pass. (Two pre-existing, unrelated failures in this suite —testShouldShowBackButton/testShouldShowBackButtonWithBioAuth— are keychain-entitlement issues in this local sandboxed environment, reproduced identically on unmodifieddev.)This response was generated by an AI agent on behalf of @JohnsonEricAtSalesforce.