Skip to content

Commit 6048a5c

Browse files
Vitali Zaidmanmeta-codesync[bot]
authored andcommitted
Add cookie URL validation check to prevent crash
Summary: Add defensive check to validate components.URL before using it to load cookies. If NSURLComponents fails to parse the URL or returns nil for components.URL, this prevents passing nil to cookiesForURL which could cause issues in the network stack. Differential Revision: D94375528
1 parent 621cc01 commit 6048a5c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ - (void)invalidate
8484
}
8585

8686
// Load and set the cookie header.
87-
NSArray<NSHTTPCookie *> *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:components.URL];
88-
request.allHTTPHeaderFields = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
87+
if (components != nil && components.URL != nil) {
88+
NSArray<NSHTTPCookie *> *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:components.URL];
89+
request.allHTTPHeaderFields = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
90+
} else {
91+
RCTLogError(@"RCTWebSocketModule: Invalid URL components - components or components.URL is nil");
92+
}
8993

9094
// Load supplied headers
9195
if ([options.headers() isKindOfClass:NSDictionary.class]) {

0 commit comments

Comments
 (0)