Closed johnfrancmartin closed 4 months ago
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Thanks for the report @johnfrancmartin
It looks like AppCheck and Firestore have different expectations about tokens and error handling for the tokenForcingRefresh
API.
FirebaseAppCheck returns nil
when there's an error : https://github.com/firebase/firebase-ios-sdk/blob/main/FirebaseAppCheck/Sources/Core/FIRAppCheck.m#L156
but Firestore still expects to return a token after an error: https://github.com/firebase/firebase-ios-sdk/blob/main/Firestore/core/src/credentials/firebase_app_check_credentials_provider_apple.mm#L88
@andrewheard Would appreciate any insights you have.
@paulb777 Firestore is actually calling the interop API getTokenForcingRefresh:completion:
, not the public API tokenForcingRefresh:completion:
. The interop API should always return the placeholder token if there's an error, never nil
.
So far I've made a sample app with the following:
import FirebaseAppCheck
import FirebaseAppCheckInterop
import FirebaseCore
import SwiftUI
class AppAttestProviderFactory: NSObject, AppCheckProviderFactory {
func createProvider(with app: FirebaseApp) -> AppCheckProvider? {
return AppAttestProvider(app: app)
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication
.LaunchOptionsKey: Any]? = nil) -> Bool {
AppCheck.setAppCheckProviderFactory(AppAttestProviderFactory())
FirebaseApp.configure()
guard let appCheckInterop = AppCheck.appCheck() as? AppCheckInterop else {
print("AppCheckInterop instance was nil.")
return false
}
appCheckInterop.getToken(forcingRefresh: true) { tokenResult in
print("AppCheckInterop: \(tokenResult.token)")
// prints "AppCheckInterop: eyJlcnJvciI6IlVOS05PV05fRVJST1IifQ=="
if let error = tokenResult.error {
print("AppCheckInterop Error: \(error)")
// prints "Error Domain=com.google.app_check_core Code=4 "The attestation provider
// AppAttestProvider is not supported on current platform and OS version. ..."
}
}
return true
}
}
The AppCheckInterop API appears to be behaving as expected, returning both the placeholder token and an error. I'll try introducing Firestore next to see if I can reproduce there.
@paulb777 I added Firestore and the code below worked:
let db = Firestore.firestore()
let citiesRef = db.collection("cities")
citiesRef.addDocument(data: ["name": "Waterloo", "country": "Canada"])
The following was printed to the console (no crash):
[FirebaseFirestore][I-FST000001] AppCheck failed: 'The operation couldn’t be completed. The attestation provider AppAttestProvider is not supported on current platform and OS version.'
@johnfrancmartin Is this a new app or did the issue appear when you upgraded to Firebase 10.19.1 from an earlier version? Do you happen to have a minimal sample app that you could share that reproduces the issue? Unfortunately I'm not able to reproduce it on my end.
Hey @johnfrancmartin. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Hey, apologies I was OOO.
Not a new app, I believe the earliest version something like this appeared in was around October of last year, and AppCheck was only added in September, so I expect it's not version related. I can't currently repro myself, so don't believe I yet know how to make a minimal sample app for this.
Don't know if it's helpful, but got another crash today:
Crashed: com.apple.root.default-qos
0 libsystem_kernel.dylib 0x9fbc __pthread_kill + 8
1 libsystem_pthread.dylib 0x5680 pthread_kill + 268
2 libsystem_c.dylib 0x75b90 abort + 180
3 libsystem_malloc.dylib 0x26200 malloc_vreport + 908
4 libsystem_malloc.dylib 0x264a8 malloc_zone_error + 104
5 libsystem_malloc.dylib 0x6a90 _szone_free + 480
6 CoreFoundation 0x1226c __CFBasicHashRehash + 1476
7 CoreFoundation 0x119a8 __CFBasicHashAddValue + 100
8 CoreFoundation 0x2c90 CFDictionarySetValue + 208
9 CFNetwork 0x20972c _CFHTTPServerResponseEnqueue + 25072
10 CFNetwork 0xdf9b8 _CFStreamErrorFromCFError + 9644
11 CFNetwork 0x211c CFURLRequestSetHTTPHeaderFieldValue + 136
12 Throwback 0x48ad88 closure #2 in StorageTokenAuthorizer.authorizeRequest(_:completionHandler:) + 64 (StorageTokenAuthorizer.swift:64)
13 Throwback 0x48af18 thunk for @escaping @callee_guaranteed (@guaranteed FIRAppCheckTokenResultInterop) -> () + 4381126424 (<compiler-generated>:4381126424)
14 Throwback 0x37cdc0 __49-[FIRAppCheck getTokenForcingRefresh:completion:]_block_invoke + 216 (FIRAppCheck.m:216)
15 Throwback 0x3874b4 __46-[GACAppCheck tokenForcingRefresh:completion:]_block_invoke + 115 (GACAppCheck.m:115)
16 Throwback 0xe8e98 __56-[FBLPromise chainOnQueue:chainedFulfill:chainedReject:]_block_invoke.33 + 273 (FBLPromise.m:273)
17 libdispatch.dylib 0x26a8 _dispatch_call_block_and_release + 32
18 libdispatch.dylib 0x4300 _dispatch_client_callout + 20
19 libdispatch.dylib 0x74cc _dispatch_queue_override_invoke + 1056
20 libdispatch.dylib 0x15be4 _dispatch_root_queue_drain + 392
21 libdispatch.dylib 0x163ec _dispatch_worker_thread2 + 156
22 libsystem_pthread.dylib 0x1928 _pthread_wqthread + 228
23 libsystem_pthread.dylib 0x1a04 start_wqthread + 8
Wanted to check-in, this issue is still going on:
Crashed: com.apple.root.default-qos
0 libsystem_kernel.dylib 0xc42c __pthread_kill + 8
1 libsystem_pthread.dylib 0x7c0c pthread_kill + 268
2 libsystem_c.dylib 0x75ba0 abort + 180
3 libsystem_malloc.dylib 0x9588 malloc_vreport + 896
4 libsystem_malloc.dylib 0x6430 malloc_zone_error + 104
5 libsystem_malloc.dylib 0x1fd4 _szone_free + 480
6 CoreFoundation 0x19464 __CFBasicHashRehash + 1476
7 CoreFoundation 0x85dc __CFBasicHashAddValue + 100
8 CoreFoundation 0x2a2e4 CFDictionarySetValue + 208
9 CFNetwork 0x9028 CFURLResponseGetExpectedContentLength + 644
10 CFNetwork 0x8e98 CFURLResponseGetExpectedContentLength + 244
11 CFNetwork 0x8240 CFURLRequestSetHTTPHeaderFieldValue + 136
12 Throwback 0x4e042c closure #2 in StorageTokenAuthorizer.authorizeRequest(_:completionHandler:) + 64 (StorageTokenAuthorizer.swift:64)
13 Throwback 0x4e05bc thunk for @escaping @callee_guaranteed (@guaranteed FIRAppCheckTokenResultInterop) -> () + 4380886460 (<compiler-generated>:4380886460)
14 Throwback 0x3d24c4 __49-[FIRAppCheck getTokenForcingRefresh:completion:]_block_invoke + 216 (FIRAppCheck.m:216)
15 Throwback 0x3dcbb8 __46-[GACAppCheck tokenForcingRefresh:completion:]_block_invoke + 115 (GACAppCheck.m:115)
16 Throwback 0x13b214 __56-[FBLPromise chainOnQueue:chainedFulfill:chainedReject:]_block_invoke.33 + 273 (FBLPromise.m:273)
17 libdispatch.dylib 0x213c _dispatch_call_block_and_release + 32
18 libdispatch.dylib 0x3dd4 _dispatch_client_callout + 20
19 libdispatch.dylib 0x6fec _dispatch_queue_override_invoke + 1056
20 libdispatch.dylib 0x15894 _dispatch_root_queue_drain + 392
21 libdispatch.dylib 0x1609c _dispatch_worker_thread2 + 156
22 libsystem_pthread.dylib 0x48f8 _pthread_wqthread + 228
23 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Adding this issue for investigation for 10.29.0
Open Questions:
appCheck.getToken(forcingRefresh: false) { tokenResult in
returns an error in tokenResult.error, is tokenResult.token nil or a placeholder?
- Why does the auth checking only fill in the header on success while app check always tries to fill in the header?
@paulb777 In App Check we're trying to differentiate between 3 states with the header:
placeholderToken
).In other words, the placeholder token allows developers to see what percentage of their user base has upgraded to a version of their app that includes App Check before switching from unenforced (monitoring) mode to enforced (to avoid prematurely blocking legitimate users before they've upgraded).
I don't think Auth has a similar concept, which is why it was only done for App Check.
We published AppCheckCore 10.19.2 for CocoaPods and Swift Package Manager that may fix this issue. We were never able to reproduce, so please update and let us know.
Description
App crashing shortly after launch, due to an issue fetching Firebase App Check token.
We're using AppAttest, with code very similar to provided default code i.e.
Reproducing the issue
No response
Firebase SDK Version
10.19.1
Xcode Version
15.0
Installation Method
Swift Package Manager
Firebase Product(s)
App Check
Targeted Platforms
iOS
Relevant Log Output
If using CocoaPods, the project's Podfile.lock
Expand
Podfile.lock
snippet```yml Replace this line with the contents of your Podfile.lock! ```