openid / AppAuth-iOS

iOS and macOS SDK for communicating with OAuth 2.0 and OpenID Connect providers.
https://openid.github.io/AppAuth-iOS
Apache License 2.0
1.76k stars 772 forks source link

OIDURLQueryComponent crashes when parameter doesn't have a value/is nil #454

Open nuke-dash opened 5 years ago

nuke-dash commented 5 years ago

Describe the bug When the redirect url contains an empty parameter the app crashes.

To Reproduce The redirect url should contain an empty parameters. Probably ?paramter1= I haven't been able to reproduce it myself as the server doesn't always give me a bad url.

Expected behavior Do not crash. Ignore the parameter.

Additional context The crash log See: 2 CoreFoundation 0x1b986ded -[__NSArrayM insertObject:atIndex:]

log.txt
# Platform: ios
# Date: 2019-09-28T16:34:00Z
# OS Version: 10.3.4 (14G61)
# Device: iPad 4
# RAM Free: 3.8%
# Disk Free: 28.6%

#0. Crashed: com.twitter.crashlytics.ios.exception
0                             0x554c09 CLSProcessRecordAllThreads + 5970953
1                             0x554c09 CLSProcessRecordAllThreads + 5970953
2                             0x554e99 CLSProcessRecordAllThreads + 5971609
3                             0x5485e9 CLSHandler + 5920233
4                             0x5538af __CLSExceptionRecord_block_invoke + 5965999
5  libdispatch.dylib              0x1b141783 _dispatch_client_callout + 22
6  libdispatch.dylib              0x1b14da35 _dispatch_barrier_sync_f_invoke + 50
7                             0x5532af CLSExceptionRecord + 5964463
8                             0x5530d7 CLSExceptionRecordNSException + 5963991
9                             0x552c8d CLSTerminateHandler() + 5962893
10 libc++abi.dylib                0x1acef98f std::__terminate(void (*)()) + 78
11 libc++abi.dylib                0x1acef493 __cxa_rethrow + 90
12 libobjc.A.dylib                0x1acfb1ab objc_exception_rethrow + 42
13 CoreFoundation                 0x1b981231 CFRunLoopRunSpecific + 600
14 CoreFoundation                 0x1b980fd1 CFRunLoopRunInMode + 104
15 GraphicsServices               0x1d12bb41 GSEventRunModal + 80
16 UIKit                          0x20d03a53 UIApplicationMain + 150
17                            0x86219 main + 23 (AppDelegate.swift:23)
18 libdyld.dylib                  0x1b16e4eb  + 2

--

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x1ba73b3d __exceptionPreprocess
1  libobjc.A.dylib                0x1acfb067 objc_exception_throw
2  CoreFoundation                 0x1b986ded -[__NSArrayM insertObject:atIndex:]
3  AppAuth                        0x121bf09 -[OIDURLQueryComponent addParameter:value:] + 103 (OIDURLQueryComponent.m:103)
4  AppAuth                        0x121bbe1 -[OIDURLQueryComponent initWithURL:] + 49 (OIDURLQueryComponent.m:49)
5  AppAuth                        0x1211f19 -[OIDAuthorizationFlowSessionImplementation resumeAuthorizationFlowWithURL:] + 115 (OIDAuthorizationService.m:115)
6                             0x506b1d specialized AppDelegate.application(_:open:sourceApplication:annotation:) + 147 (AppDelegate.swift:147)
7                             0x506075 @objc AppDelegate.application(_:open:sourceApplication:annotation:) ()
8  UIKit                          0x20f1d3bf __45-[UIApplication _applicationOpenURL:payload:]_block_invoke
9  UIKit                          0x20f1ce0d -[UIApplication _applicationOpenURL:payload:]
10 SafariServices                 0x289c0d6b -[SFSafariViewController remoteViewController:hostApplicationOpenURL:]
11 SafariServices                 0x289b84e9 -[SFBrowserRemoteViewController willOpenURLInHostApplication:]
12 CoreFoundation                 0x1ba78354 __invoking___
13 CoreFoundation                 0x1b99c2b9 -[NSInvocation invoke]
14 FrontBoardServices             0x1d354c13 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
15 FrontBoardServices             0x1d354acd -[FBSSerialQueue _performNext]
16 FrontBoardServices             0x1d354db7 -[FBSSerialQueue _performNextFromRunLoopSource]
17 CoreFoundation                 0x1ba2ffdd __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
18 CoreFoundation                 0x1ba2fb05 __CFRunLoopDoSources0
19 CoreFoundation                 0x1ba2df51 __CFRunLoopRun
20 CoreFoundation                 0x1b9811af CFRunLoopRunSpecific
21 CoreFoundation                 0x1b980fd1 CFRunLoopRunInMode
22 GraphicsServices               0x1d12bb41 GSEventRunModal
23 UIKit                          0x20d03a53 UIApplicationMain
24                            0x86219 main + 23 (AppDelegate.swift:23)
25 libdyld.dylib                  0x1b16e4eb (Missing)

#0. Crashed: com.twitter.crashlytics.ios.exception
0                             0x554c09 CLSProcessRecordAllThreads + 5970953
1                             0x554c09 CLSProcessRecordAllThreads + 5970953
2                             0x554e99 CLSProcessRecordAllThreads + 5971609
3                             0x5485e9 CLSHandler + 5920233
4                             0x5538af __CLSExceptionRecord_block_invoke + 5965999
5  libdispatch.dylib              0x1b141783 _dispatch_client_callout + 22
6  libdispatch.dylib              0x1b14da35 _dispatch_barrier_sync_f_invoke + 50
7                             0x5532af CLSExceptionRecord + 5964463
8                             0x5530d7 CLSExceptionRecordNSException + 5963991
9                             0x552c8d CLSTerminateHandler() + 5962893
10 libc++abi.dylib                0x1acef98f std::__terminate(void (*)()) + 78
11 libc++abi.dylib                0x1acef493 __cxa_rethrow + 90
12 libobjc.A.dylib                0x1acfb1ab objc_exception_rethrow + 42
13 CoreFoundation                 0x1b981231 CFRunLoopRunSpecific + 600
14 CoreFoundation                 0x1b980fd1 CFRunLoopRunInMode + 104
15 GraphicsServices               0x1d12bb41 GSEventRunModal + 80
16 UIKit                          0x20d03a53 UIApplicationMain + 150
17                            0x86219 main + 23 (AppDelegate.swift:23)
18 libdyld.dylib                  0x1b16e4eb  + 2

#1. com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x1b22c900 mach_msg_trap + 20
1  libsystem_kernel.dylib         0x1b22c6e1 mach_msg + 44
2  CoreFoundation                 0x1ba2fbe3 __CFRunLoopServiceMachPort + 144
3  CoreFoundation                 0x1ba2e065 __CFRunLoopRun + 1436
4  CoreFoundation                 0x1b9811af CFRunLoopRunSpecific + 470
5  CoreFoundation                 0x1b980fd1 CFRunLoopRunInMode + 104
6  Foundation                     0x1c2d5af5  + 258
7  Foundation                     0x1c2f276d  + 86
8  UIKit                          0x21604ad9 -[UIEventFetcher threadMain] + 128
9  Foundation                     0x1c3b98eb  + 1122
10 libsystem_pthread.dylib        0x1b2f893b _pthread_body + 216
11 libsystem_pthread.dylib        0x1b2f885d _pthread_start + 234
12 libsystem_pthread.dylib        0x1b2f6468 thread_start + 8

#2. AVAudioSession Notify Thread
0  libsystem_kernel.dylib         0x1b22c900 mach_msg_trap + 20
1  libsystem_kernel.dylib         0x1b22c6e1 mach_msg + 44
2  CoreFoundation                 0x1ba2fbe3 __CFRunLoopServiceMachPort + 144
3  CoreFoundation                 0x1ba2e065 __CFRunLoopRun + 1436
4  CoreFoundation                 0x1b9811af CFRunLoopRunSpecific + 470
5  CoreFoundation                 0x1b980fd1 CFRunLoopRunInMode + 104
6  AVFAudio                       0x3200b82f GenericRunLoopThread::Entry(void*) + 142
7  AVFAudio                       0x3203458f CAPThread::Entry(CAPThread*) + 154
8  libsystem_pthread.dylib        0x1b2f893b _pthread_body + 216
9  libsystem_pthread.dylib        0x1b2f885d _pthread_start + 234
10 libsystem_pthread.dylib        0x1b2f6468 thread_start + 8

#3. com.twitter.crashlytics.ios.MachExceptionServer
0  libsystem_kernel.dylib         0x1b22c900 mach_msg_trap + 20
1  libsystem_kernel.dylib         0x1b22c6e1 mach_msg + 44
2                             0x544103 CLSMachExceptionServer + 5902595
3  libsystem_pthread.dylib        0x1b2f893b _pthread_body + 216
4  libsystem_pthread.dylib        0x1b2f885d _pthread_start + 234
5  libsystem_pthread.dylib        0x1b2f6468 thread_start + 8

#4. com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x1b22c900 mach_msg_trap + 20
1  libsystem_kernel.dylib         0x1b22c6e1 mach_msg + 44
2  CoreFoundation                 0x1ba2fbe3 __CFRunLoopServiceMachPort + 144
3  CoreFoundation                 0x1ba2e065 __CFRunLoopRun + 1436
4  CoreFoundation                 0x1b9811af CFRunLoopRunSpecific + 470
5  CoreFoundation                 0x1b980fd1 CFRunLoopRunInMode + 104
6  CFNetwork                      0x1c05e393 +[NSURLConnection(Loader) _resourceLoadLoop:] + 402
7  Foundation                     0x1c3b98eb  + 1122
8  libsystem_pthread.dylib        0x1b2f893b _pthread_body + 216
9  libsystem_pthread.dylib        0x1b2f885d _pthread_start + 234
10 libsystem_pthread.dylib        0x1b2f6468 thread_start + 8

#5. Thread
0  libsystem_kernel.dylib         0x1b241808 __psynch_cvwait + 24
1  libsystem_pthread.dylib        0x1b2f7c43 _pthread_cond_wait + 560
2  libsystem_pthread.dylib        0x1b2f8fc5 pthread_cond_wait + 38
3  libc++.1.dylib                 0x1ac93c57 std::__1::condition_variable::wait(std::__1::unique_lock&) + 118
4  JavaScriptCore                 0x1f8e8261  + 88
5  JavaScriptCore                 0x1f8e81e5  + 154
6  JavaScriptCore                 0x1f8e80ed  + 18
7  JavaScriptCore                 0x1f8e832f  + 66
8  libsystem_pthread.dylib        0x1b2f893b _pthread_body + 216
9  libsystem_pthread.dylib        0x1b2f885d _pthread_start + 234
10 libsystem_pthread.dylib        0x1b2f6468 thread_start + 8

#6. Thread
0  libsystem_kernel.dylib         0x1b24273c __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1b2f68eb _pthread_wqthread + 1150
2  libsystem_pthread.dylib        0x1b2f645c start_wqthread + 8

#7. Thread
0  libsystem_kernel.dylib         0x1b24273c __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1b2f6745 _pthread_wqthread + 728
2  libsystem_pthread.dylib        0x1b2f645c start_wqthread + 8

#8. Thread
0  libsystem_kernel.dylib         0x1b24273c __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1b2f6745 _pthread_wqthread + 728
2  libsystem_pthread.dylib        0x1b2f645c start_wqthread + 8
guidedways commented 5 years ago

Same here:

Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x191f3698c __exceptionPreprocess 1 libobjc.A.dylib 0x19110f9f8 objc_exception_throw 2 CoreFoundation 0x191eb03f8 _CFArgv 3 CoreFoundation 0x191e210cc -[__NSArrayM insertObject:atIndex:] 4 AppAuth 0x10186aa80 -[OIDURLQueryComponent addParameter:value:] + 117 (OIDURLQueryComponent.m:117) 5 AppAuth 0x1018692cc -[OIDTokenRequest URLRequest] + 297 (OIDTokenRequest.m:297) 6 AppAuth 0x10185d170 +[OIDAuthorizationService performTokenRequest:originalAuthorizationResponse:callback:] + 433 (OIDAuthorizationService.m:433) 7 AppAuth 0x1018603e4 -[OIDAuthState performActionWithFreshTokens:additionalRefreshParameters:dispatchQueue:] + 513 (OIDAuthState.m:513) 8 AppAuth 0x101860178 -[OIDAuthState performActionWithFreshTokens:additionalRefreshParameters:] + 465 (OIDAuthState.m:465) 9 GTMAppAuth 0x1018a908c -[GTMAppAuthFetcherAuthorization authorizeRequestArgs:] + 235 (GTMAppAuthFetcherAuthorization.m:235) 10 GTMAppAuth 0x1018a9ed8 -[GTMAppAuthFetcherAuthorization authorizeRequest:completionHandler:] + 447 (GTMAppAuthFetcherAuthorization.m:447)

guidedways commented 5 years ago

This is pretty serious - anyone doing anything about this? We've had 353 crashes reported in just 1 day and growing.

wilmarvh commented 4 years ago

Same as this potentially? https://github.com/openid/AppAuth-iOS/issues/215

abdulrehman89 commented 1 year ago

any luck on this issue? i am having same issue, NSURLComponents making query items and adding in paraneters without nil check

abdulrehman89 commented 1 year ago

@wilmarvh {scheme = eclectic, user = (null), password = (null), host = (null), port = (null), path = /oauth2redirect, query = &code=192e421f-4b0b-11ee-a9a6-fa163eef2e72&state=xxkDWGnVa56Qr8SjUgaVHc0DwmVBjDLJyQM1ka7t9kE&offre_id=117, fragment = (null)} when adding these parameters, its crashing on OIDURLQueryComponent