Skip to content

Commit bbc05d8

Browse files
vzaidmanfacebook-github-bot
authored andcommitted
Add URL validation check to prevent crash (facebook#55748)
Summary: Add defensive check to validate the WebSocket URL before attempting to connect. This prevents potential crashes when an invalid or nil URL is passed to the WebSocket module, which could cause XPC serialization failures deep in the network stack. The crash was observed in during XPC serialization when SocketRocket attempted to open a connection with invalid URL data. Changelog: [Internal] Reviewed By: javache Differential Revision: D94375527
1 parent e5d2d95 commit bbc05d8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/react-native/React/CoreModules/RCTWebSocketModule.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import <objc/runtime.h>
1111

1212
#import <FBReactNativeSpec/FBReactNativeSpec.h>
13+
#import <React/RCTAssert.h>
1314
#import <React/RCTConvert.h>
1415
#import <React/RCTUtils.h>
1516
#import <SocketRocket/SRWebSocket.h>
@@ -66,6 +67,12 @@ - (void)invalidate
6667
connect : (NSURL *)URL protocols : (NSArray *)protocols options : (JS::NativeWebSocketModule::SpecConnectOptions &)
6768
options socketID : (double)socketID)
6869
{
70+
if (URL == nil || URL.absoluteString.length == 0u) {
71+
RCTAssert(NO, @"RCTWebSocketModule: Invalid WebSocket URL passed to connect");
72+
[self sendEventWithName:@"websocketFailed" body:@{@"message" : @"Invalid WebSocket URL", @"id" : @(socketID)}];
73+
return;
74+
}
75+
6976
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
7077

7178
// We load cookies from sharedHTTPCookieStorage (shared with XHR and

0 commit comments

Comments
 (0)