Skip to content

Commit 3ff5bcc

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] Differential Revision: D94375527
1 parent d1b2ddc commit 3ff5bcc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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

Lines changed: 9 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,14 @@ - (void)invalidate
6667
connect : (NSURL *)URL protocols : (NSArray *)protocols options : (JS::NativeWebSocketModule::SpecConnectOptions &)
6768
options socketID : (double)socketID)
6869
{
70+
if ((URL == nullptr) || URL.absoluteString.length == 0u) {
71+
RCTAssert(NO, @"RCTWebSocketModule: Invalid WebSocket URL passed to connect");
72+
NSNumber *socketIDNumber = @(socketID);
73+
NSDictionary *body = @{@"message" : @"Invalid WebSocket URL", @"id" : socketIDNumber};
74+
[self sendEventWithName:@"websocketFailed" body:body];
75+
return;
76+
}
77+
6978
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
7079

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

0 commit comments

Comments
 (0)