Android: new WebSocket() crashes the app for a URL that OkHttp or java.net.URI rejects
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
調査の方向性
com.facebook.react.modules.websocket.WebSocketModule.java を読み、connect メソッドで Request.Builder().url(url)、getCookie、getDefaultOrigin が呼び出されるところを特定する。これらの呼び出しを IllegalArgumentException の try-catch で囲み、send と close が行うように JS に error/close イベントを dispatch する。Done は、無効な URL がアプリをクラッシュさせる代わりに WebSocket で error と close を発生させることを意味する。
索引モデルが issue の本文から書いたものです。
説明
Description
On Android, new WebSocket(url) crashes the app when OkHttp or java.net.URI rejects url, such as ws://localhost:0/ (port 0) or ws://localhost:4000/a|b (a character RFC 2396 doesn't allow in a path). JavaScript gets no exception and no error or close event, and a release build dies with a fatal exception on the native modules thread.
Expected: the socket fires error and close, as it does when it can't connect, or the constructor throws in JavaScript.
Likely cause: WebSocketModule.connect calls Request.Builder().url(url), getCookie, and getDefaultOrigin outside a try, and they throw IllegalArgumentException for such URLs, while send and close catch their exceptions. #24427 reported the same crash in 0.59.
We found this in Evolu, a local-first platform, whose relay URL type now rejects such URLs.
Steps to reproduce
- Replace
App.tsxof an app made from the reproducer template with the code below. - Build it in release for Android and run it.
- Tap either button. The app crashes instead of showing
errorandclose.
import { useState } from 'react';
import { Button, Text, View } from 'react-native';
// Each URL should report an error and close to JS. On Android, connect throws
// natively instead.
const urls = ['ws://localhost:0/', 'ws://localhost:4000/a|b'];
function App() {
const [log, setLog] = useState<ReadonlyArray<string>>([]);
const append = (line: string) => setLog(lines => [...lines, line]);
return (
<View style={{ padding: 48, gap: 16 }}>
{urls.map(url => (
<Button
key={url}
title={url}
onPress={() => {
const socket = new WebSocket(url);
socket.onerror = () => append(`error ${url}`);
socket.onclose = event => append(`close ${url} ${event.code}`);
}}
/>
))}
{log.map((line, index) => (
<Text key={index}>{line}</Text>
))}
</View>
);
}
export default App;
React Native Version
0.88.1
Affected Platforms
Runtime - Android, Build - MacOS
Output of npx @react-native-community/cli info
System:
OS: macOS 26.6.2
CPU: (10) arm64 Apple M5
Binaries:
Node: 24.22.0
npmPackages:
react-native: 0.88.1
Android:
hermesEnabled: true
newArchEnabled: true
Device: Android 16 (API 36) arm64 emulator
Stacktrace or Logs
E AndroidRuntime: FATAL EXCEPTION: mqt_v_native
E AndroidRuntime: java.lang.IllegalArgumentException: Invalid URL port: "0"
E AndroidRuntime: at t6.m(r8-map-id-50fb0331…:24)
E AndroidRuntime: at vv.c(r8-map-id-50fb0331…:513)
E AndroidRuntime: at xi.h(r8-map-id-50fb0331…:50)
E AndroidRuntime: at com.facebook.react.modules.websocket.WebSocketModule.connect(r8-map-id-50fb0331…:118)
E AndroidRuntime: at com.facebook.jni.NativeRunnable.run(Native Method)
E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(…)
E AndroidRuntime: FATAL EXCEPTION: mqt_v_native
E AndroidRuntime: java.lang.IllegalArgumentException: Unable to set ws://localhost:4000/a|b as default origin header
E AndroidRuntime: at com.facebook.react.modules.websocket.WebSocketModule.getCookie(r8-map-id-50fb0331…:8)
E AndroidRuntime: at com.facebook.react.modules.websocket.WebSocketModule.connect(r8-map-id-50fb0331…:121)
MANDATORY Reproducer
No repository: the App.tsx in Steps to reproduce is the whole reproducer.
Screenshots and Videos
No response
- 主要言語
- C++
- スター
- 127k
- フォーク
- 25.4k
- 平均マージ
- 3日 1時間
- マージ済み PR(30日)
- 108
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
react/react-native のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
react/react-native#59722 ·
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
react/react-native#59694 ·
メンテナーはふだん 2 日以内に返信
-
Image.resolveAssetSource's TypeScript declaration drops the null it returns for an unknown asset対応中かも @Hassan1305 が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
react/react-native#59648 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Linking.getInitialURL() returns the task's first link after a link relaunches a reclaimed Android app対応中かも @YevheniiKotyrlo が 21 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
react/react-native#59006 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
Fabric TextInput: prepareForRecycle leaves stale inputAccessoryViewButtonLabel (empty Done bar)対応中かも @jkasprzyk17 が 20 日前に担当しました。 オープンNeeds: Author Feedback Needs: Repro
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
react/react-native#58952 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
react/react-native の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
meshcore-dev/MeshCore#3760 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
deepseek-ai/DeepGEMM-Ascend#29 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
EchoTools/nevr-runtime#2042 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
emscripten-core/emscripten#28160 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Download size and speed show scientific notation between 1000 and 1023 units対応中かも @RaphaelFakhri が今日担当しました。 オープン
難易度 2/5 1時間未満 初心者へのやさしさ 88/100
kiwix/kiwix-desktop#1570 ·
メンテナーはふだん 1 日以内に返信