react / react/react-native

Commas in cookie value not parsed correctly on Android

オープン
#29,916 コメント 12 件 リアクション 7 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Needs: Triage :mag: Never gets stale Platform: Android Platform: Linux
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
4

説明

Description

tl;dr Commas are treated as cookie deliminators on Android only

Commas (,) in cookie values are not allowed as part of the cookie specification but they're still allowed on all major browsers and through iOS's networking APIs. However in Android okhttp (specifically okhttp3.JavaNetCookieJar) commas are treated as cookie delimiters in the same way that semicolons are. This behaviour isn't mentioned anywhere and is inconsistent with iOS/Web.

I have found an existing issue on okhttp which suggests the regular CookieJar doesn't have this limitation and should be used instead of JavaNetCookieJar. I can also confirm that removing the comma here fixes the issue. React Native sets the okhttp cookie jar to JavaNetCookieJar here.

I'm working with an external service which I can't control so changing the cookie isn't an option. Because {redirect: "manual"} doesn't work in React Native iOS/Android, it's impossible to override this behaviour if the cookie is set in a 302 response and required for subsequent responses.

React Native version:

System:
    OS: Linux 5.3 Linux Mint 19.1 (Tessa)
    CPU: (4) x64 Intel(R) Core(TM) m3-6Y30 CPU @ 0.90GHz
    Memory: 1.50 GB / 7.67 GB
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 10.15.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 6.4.1 - /usr/local/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK:
      Android NDK: 17.2.4988734
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 11.0.3 - /usr/bin/javac
    Python: 2.7.17 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: ~16.11.0 => 16.11.0 
    react-native: github:facebook/react-native#0.63-stable => 0.63.2 
  npmGlobalPackages:

Steps To Reproduce and expected results

If a fetch request is made to a server which responds with the following header:

Set-Cookie: TestCookie=a:hello,b:goodbye

On every platform apart from Android, the following Cookie header is sent in future requests:

Cookie: TestCookie=a:hello,b:goodbye;

but on Android the cookie is parsed incorrectly and the following header is sent (2 cookies):

Cookie: TestCookie=a:hello;b:goodbye=;

Snack, code example, screenshot, or link to a repository:

To easily reproduce this, run this express project https://gist.github.com/uen/f8bbded0fc10fd2d3910d388cd3fea6e and load snack https://snack.expo.io/8y09x_Bc7 on a real Android and iOS device (and web). The Android cookie will not be correct as described above

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java と、参照されている okhttp3 JavaNetCookieJar.kt の動作から始めてください。リンクされた Express プロジェクトと Snack を Android で実行し、生成された Cookie ヘッダーを iOS および Web と比較してください。Android で Cookie 値内のカンマがそのまま保持されるか、依存関係の制限が明確に文書化されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
android, react-native
領域
mobile, networking
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。