diff --git a/android/src/main/cpp/sonar.cpp b/android/src/main/cpp/sonar.cpp index 3bfa8d3a350..d9415668ebf 100644 --- a/android/src/main/cpp/sonar.cpp +++ b/android/src/main/cpp/sonar.cpp @@ -343,6 +343,13 @@ class JFlipperWebSocket : public facebook::flipper::FlipperSocket { if (socket_ == nullptr) { return; } + // Ensure the payload size is valid before sending. + // The maximum allowed size for a message payload is 2^53 - 1. But that is + // for the entire message, including any additional metadata. + if (message.length() > pow(2, 53) - 1) { + throw std::length_error("Payload is too big to send"); + } + socket_->send(message); completion(); } diff --git a/iOS/FlipperKit/FlipperWebSocket.mm b/iOS/FlipperKit/FlipperWebSocket.mm index 53529b88274..241f096e06a 100644 --- a/iOS/FlipperKit/FlipperWebSocket.mm +++ b/iOS/FlipperKit/FlipperWebSocket.mm @@ -121,6 +121,14 @@ if (socket_ == NULL) { return; } + + // Ensure the payload size is valid before sending. + // The maximum allowed size for a message payload is 2^53 - 1. But that is + // for the entire message, including any additional metadata. + if (message.length() > pow(2, 53) - 1) { + throw std::length_error("Payload is too big to send"); + } + NSString* messageObjc = [NSString stringWithUTF8String:message.c_str()]; [socket_ send:messageObjc withCompletionHandler:^(NSError*) {