react-native-cookies icon indicating copy to clipboard operation
react-native-cookies copied to clipboard

Crash when loading session cookie

Open lukecyca opened this issue 6 years ago • 4 comments

Platform: iOS

Version: master (f11374745deba9f18f7b8a9bb4b0b2573026f522)

Steps to reproduce:

  1. Use fetch() to hit an endpoint that sets a cookie with no expiry (ie: a session cookie). For example set-cookie: foo=bar; Path=/; HttpOnly
  2. Call CookieManager.get("https://example.com");

The result is the following stacktrace:

Exception '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: expiresDate)' was thrown while invoking get on target RNCookieManagerIOS with params (
    "https://app.example.com",
    0,
    24,
    25
)
callstack: (
	0   CoreFoundation                      0x00000001123e929b __exceptionPreprocess + 331
	1   libobjc.A.dylib                     0x0000000110641735 objc_exception_throw + 48
	2   CoreFoundation                      0x00000001123338fc _CFThrowFormattedException + 194
	3   CoreFoundation                      0x000000011245b3f6 -[__NSDictionaryM setObject:forKey:] + 1046
	4   CM_App                              0x000000010f9c8380 -[RNCookieManagerIOS get:useWebKit:resolver:rejecter:] + 1584
	5   CoreFoundation                      0x00000001123f011c __invoking___ + 140
	6   CoreFoundation                      0x00000001123ed5b5 -[NSInvocation invoke] + 325
	7   CoreFoundation                      0x00000001123eda06 -[NSInvocation invokeWithTarget:] + 54
	8   CM_App                              0x000000010f78a25a -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2810
	9   CM_App                              0x000000010f845f96 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 790
	10  CM_App                              0x000000010f845aaf _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 127
	11  CM_App                              0x000000010f845a29 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
	12  libdispatch.dylib                   0x000000011526e51d _dispatch_call_block_and_release + 12
	13  libdispatch.dylib                   0x000000011526f587 _dispatch_client_callout + 8
	14  libdispatch.dylib                   0x0000000115276058 _dispatch_lane_serial_drain + 720
	15  libdispatch.dylib                   0x0000000115276b9b _dispatch_lane_invoke + 401
	16  libdispatch.dylib                   0x000000011527f9c6 _dispatch_workloop_worker_thread + 645
	17  libsystem_pthread.dylib             0x000000011564ffd2 _pthread_wqthread + 980
	18  libsystem_pthread.dylib             0x000000011564fbe9 start_wqthread + 13
)

lukecyca avatar Nov 06 '18 22:11 lukecyca

Looks like this was introduced in the latest commit. Paging @marcshilling.

lukecyca avatar Nov 07 '18 00:11 lukecyca

Surprising that the expiresDate would ever be nil, but we should be able to protect against by wrapping that line with a nil check. I'll make a PR.

marcshilling avatar Nov 07 '18 00:11 marcshilling

Even if i set expiration app crashes. do we have a solution for it.

avinash03031991 avatar Aug 13 '19 08:08 avinash03031991

I have forked the repo here: https://github.com/safaiyeh/react-native-cookie-store We can create issues and PRs there to continue the development of the project.

safaiyeh avatar Jan 02 '20 19:01 safaiyeh