Skip to content

Commit 141c956

Browse files
huntiefacebook-github-bot
authored andcommitted
Validate max requestable IO.read size (#53063)
Summary: Pull Request resolved: #53063 Update `IO.read` CDP method handler to validate the received `size` parameter. This now accepts a max value of 10MB — adding a layer of safety in front of our current Android implementation, which fails at around ~15MB due to OkHttp limits. Changelog: [Internal] Reviewed By: vzaidman Differential Revision: D79646155 fbshipit-source-id: c777802105dc31cdcc7e9e960c880e689540fddd
1 parent 0f0a3cf commit 141c956

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

packages/react-native/ReactCommon/jsinspector-modern/NetworkIOAgent.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace facebook::react::jsinspector_modern {
2222

2323
static constexpr long DEFAULT_BYTES_PER_READ =
2424
1048576; // 1MB (Chrome v112 default)
25+
static constexpr unsigned long MAX_BYTES_PER_READ = 10485760; // 10MB
2526

2627
// https://github.com/chromium/chromium/blob/128.0.6593.1/content/browser/devtools/devtools_io_context.cc#L71-L73
2728
static constexpr std::array kTextMIMETypePrefixes{
@@ -403,9 +404,17 @@ void NetworkIOAgent::handleIoRead(const cdp::PreparsedRequest& req) {
403404
"Invalid params: handle is missing or not a string."));
404405
return;
405406
}
406-
std::optional<unsigned long> size = std::nullopt;
407+
std::optional<int64_t> size = std::nullopt;
407408
if ((req.params.count("size") != 0u) && req.params.at("size").isInt()) {
408409
size = req.params.at("size").asInt();
410+
411+
if (size > MAX_BYTES_PER_READ) {
412+
frontendChannel_(cdp::jsonError(
413+
requestId,
414+
cdp::ErrorCode::InvalidParams,
415+
"Invalid params: size cannot be greater than 10MB."));
416+
return;
417+
}
409418
}
410419

411420
auto streamId = req.params.at("handle").asString();

packages/react-native/ReactCommon/jsinspector-modern/tests/HostTargetTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,4 +1501,26 @@ TEST_F(HostTargetTest, NetworkLoadNetworkResource3xx) {
15011501
});
15021502
}
15031503

1504+
TEST_F(HostTargetTest, IOReadSizeValidation) {
1505+
connect();
1506+
1507+
InSequence s;
1508+
1509+
EXPECT_CALL(fromPage(), onMessage(JsonEq(R"({
1510+
"id": 1,
1511+
"error": {
1512+
"message": "Invalid params: size cannot be greater than 10MB.",
1513+
"code": -32602
1514+
}
1515+
})")));
1516+
toPage_->sendMessage(R"({
1517+
"id": 1,
1518+
"method": "IO.read",
1519+
"params": {
1520+
"handle": "0",
1521+
"size": 134217728
1522+
}
1523+
})");
1524+
}
1525+
15041526
} // namespace facebook::react::jsinspector_modern

0 commit comments

Comments
 (0)