Skip to content

Commit 36607b6

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
1 parent 41677c8 commit 36607b6

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
@@ -86,8 +86,12 @@ - (void)invalidate
8686
}
8787

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

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

0 commit comments

Comments
 (0)