Commit 0eb9b30
Fix Android WebSocket cookie lookup stripping the URL path (#58365)
Summary:
`WebSocketModule.getCookie` looks up cookies through `getDefaultOrigin(uri)`, which strips the URL down to `scheme://host[:port]` before handing it to `ForwardingCookieHandler`. Android's `CookieManager` matches cookies against the full URL (domain and path), so any cookie set with a `Path` other than `/` gets silently dropped from the WebSocket handshake, breaking auth/session cookies scoped to a sub-path (e.g. `/signal-r/hubs/messages`).
`getDefaultOrigin` is also used to build the `origin` header 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 separate `getCookieLookupUri` that does the same `ws(s)://` to `http(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
Pull Request resolved: #58365
Test Plan:
Added `WebSocketModuleTest`, exercising `getCookieLookupUri` through 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-plugin` isn't resolvable without the full monorepo build), so I compiled the real companion object with `kotlinc` standalone and ran the same reflection lookup against it directly, confirming both cases pass and that the private companion method resolves without a `NoSuchMethodException`.
Fixes #58358
Reviewed By: cipolleschi
Differential Revision: D119093059
Pulled By: javache
fbshipit-source-id: c5404937c97b497d3eae8c45433785f057602c291 parent 07a6e1f commit 0eb9b30
2 files changed
Lines changed: 79 additions & 9 deletions
File tree
- packages/react-native/ReactAndroid/src
- main/java/com/facebook/react/modules/websocket
- test/java/com/facebook/react/modules/websocket
Lines changed: 38 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | | - | |
| 430 | + | |
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| |||
459 | 459 | | |
460 | 460 | | |
461 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
462 | 472 | | |
463 | 473 | | |
464 | 474 | | |
| |||
468 | 478 | | |
469 | 479 | | |
470 | 480 | | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
| 481 | + | |
479 | 482 | | |
480 | 483 | | |
481 | 484 | | |
| |||
489 | 492 | | |
490 | 493 | | |
491 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
492 | 521 | | |
493 | 522 | | |
Lines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments