Skip to content

Commit 312d58e

Browse files
vzaidmanmeta-codesync[bot]
authored andcommitted
Add cookie URL validation check to prevent crash (#55787)
Summary: Pull Request resolved: #55787 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. Changelog: [Internal] Reviewed By: javache Differential Revision: D94375528 fbshipit-source-id: 499b9ed9c7661b43819b0a2b15edd62775d380f7
1 parent d5b2827 commit 312d58e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

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)