Skip to content

fix(auth): keep the session id when the continue URL already has a query - #2497

Open
demolaf wants to merge 4 commits into
version-10.0.0-beta05from
fix/continue-url-existing-query
Open

fix(auth): keep the session id when the continue URL already has a query#2497
demolaf wants to merge 4 commits into
version-10.0.0-beta05from
fix/continue-url-existing-query

Conversation

@demolaf

@demolaf demolaf commented Sep 9, 2026

Copy link
Copy Markdown
Member

ContinueUrlBuilder appended ? unconditionally and then picked each parameter's separator by checking whether the last character was ?. When a consumer's continue URL already had a query string the result carried two ? and the first appended parameter was glued onto the consumer's last value — always ui_sid, the same-device session identifier, so isDifferentDevice read the same device as a different one and email-link sign-in showed a spurious cross-device prompt. Parameters were also appended after a # fragment, where they aren't query parameters at all, and values were interpolated raw.

The builder no longer does string surgery: it parses the URL once with Uri and appends through buildUpon().appendQueryParameter(...), the same parser EmailLinkParser reads the parameters back with. Separator choice, fragment placement and percent-encoding all become the platform's job instead of something this class infers. A URL with nothing appended comes back unchanged.

Added ContinueUrlBuilderTest and EmailLinkParserTest — 27 tests, Robolectric so the URLs are read back through the real android.net.Uri. Neither class had any tests before; verified they fail on the old code and pass with the fix.


Maintainer note: Fixes internal CPRN-434

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request refactors ContinueUrlBuilder to correctly handle incoming URLs that already contain query parameters or fragments, ensuring appended parameters are correctly placed before the fragment. It also adds comprehensive unit tests for ContinueUrlBuilder and EmailLinkParser. The feedback recommends URL-encoding the parameter values appended to the continue URL to prevent breaking the URL structure with special characters, and adding a corresponding unit test to verify this behavior.

Comment thread auth/src/main/java/com/firebase/ui/auth/util/ContinueUrlBuilder.kt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant