Fix Android WebSocket cookie lookup stripping the URL path - #58365
Closed
lazerg wants to merge 2 commits into
Closed
Fix Android WebSocket cookie lookup stripping the URL path#58365lazerg wants to merge 2 commits into
lazerg wants to merge 2 commits into
Conversation
javache
reviewed
Sep 7, 2026
Comment on lines
+512
to
+513
| requestURI.query, | ||
| requestURI.fragment, |
Contributor
There was a problem hiding this comment.
Why do we need to include query and fragment?
Can we simplify this method to only re-create the URI if the scheme is ws(s)?
Contributor
Author
There was a problem hiding this comment.
Simplified in 476697c: getCookieLookupUri now passes null for query and fragment instead of forwarding them through, so the lookup URI is just scheme://host[:port]/path.
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D119093059. |
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:
WebSocketModule.getCookielooks up cookies throughgetDefaultOrigin(uri), which strips the URL down toscheme://host[:port]before handing it toForwardingCookieHandler. Android'sCookieManagermatches cookies against the full URL (domain and path), so any cookie set with aPathother than/gets silently dropped from the WebSocket handshake, breaking auth/session cookies scoped to a sub-path (e.g./signal-r/hubs/messages).getDefaultOriginis also used to build theoriginheader for the handshake, where stripping the path is correct per the WebSocket protocol, so it can't just be changed in place without affecting that header too. This adds a separategetCookieLookupUrithat does the samews(s)://tohttp(s)://scheme mapping but keeps the path, query, and fragment, and uses it only for the cookie lookup. It also drops the URI's userinfo from that lookup, since it plays no role in cookie matching and shouldn't be forwarded into the CookieManager call.Changelog:
[ANDROID] [FIXED] - Fix WebSocket cookie lookup dropping path-scoped cookies
Test Plan:
Added
WebSocketModuleTest, exercisinggetCookieLookupUrithrough reflection and asserting the path, port, and query survive the ws/wss -> http/https conversion. Couldn't run it through the repo's own Gradle/Robolectric setup in this environment (react-native-gradle-pluginisn't resolvable without the full monorepo build), so I compiled the real companion object withkotlincstandalone and ran the same reflection lookup against it directly, confirming both cases pass and that the private companion method resolves without aNoSuchMethodException.Fixes #58358