Open yasuradodo opened 3 years ago
We have the same issue. 1K crashes in one hour. I will be tracking this post and adding any updates from our side 👍
My findings:
TWTRGuestAuthRequestSigner.m#L31
[mutableRequest setValue:session.guestToken forHTTPHeaderField:TWTRGuestTokenHeaderField];
^ From the crash report we can tell that session.guestToken
is a NSNumber
when it should be an NSString
.
Chasing the guestToken
through many files, we get to its source: It's retrieved from Twitter's servers which provide a JSON response that's deserialized here:
TWTRAuthenticationProvider.m#L38
json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
Meaning Twitter changed the token it returns from string
to number
.
The recommended fix would be something like this: TWTRGuestSession.m#L47
- NSString *guestToken = sessionDictionary[TWTRGuestAuthOAuthTokenKey];
+ NSString *guestToken = nil;
+ id rawToken = sessionDictionary[TWTRGuestAuthOAuthTokenKey];
+ if ([rawToken isKindOfClass:NSNumber.class]) {
+ guestToken = [(NSNumber *)rawToken stringValue];
+ } else {
+ guestToken = (NSString *)rawToken;
+ }
(assuming Twitter's API accepts their token as a string in later requests)
We have not tried/confirmed the fix yet since we cannot reproduce the crash. If you're able to reproduce it, please give it a try.
I was able to reproduce this using a jailbroken device and modifying (NSURLRequest *)signedURLRequest:(NSURLRequest *)URLRequest session:(TWTRGuestSession *)session
at runtime:
%hook TWTRGuestAuthRequestSigner
+(NSURLRequest *)signedURLRequest:(NSURLRequest *)URLRequest session:(TWTRGuestSession *)session {
NSLog(@"request");
NSMutableURLRequest *mutableRequest = [URLRequest mutableCopy];
\\here is where I replaced the guestToken with an NSNumber
[mutableRequest setValue:[NSNumber numberWithInt: 0123123] forHTTPHeaderField:TWTRGuestTokenHeaderField];
NSString *appToken = [NSString stringWithFormat:@"Bearer %@", session.accessToken];
[mutableRequest setValue:appToken forHTTPHeaderField:TWTRAuthorizationHeaderField];
return mutableRequest;
}
%end
I was able to replicate the crash in Xcode. It is exactly the same or at least very similar as I've been seeing in my logs.
It is in fact due to guestToken
not being of type NSString
since NSNumber
doesn't have a length
method.
Twitter seems to have fixed their mistake since our crashes have basically stopped. We still have zero acknowledgment of the issue from Twitter though.
Twitter seems to have fixed their mistake since our crashes have basically stopped. We still have zero acknowledgment of the issue from Twitter though.
Same in my project. It's stoped about 10 hours ago.
I cannot reproduced the issue, but I got +5k crash reports in this past few hours from our app.
Seems the crash is happened inside of TWTRAPIClient.
My code
Does anyone have same issue?