Repository navigation
Description
Description
On iOS, our app crashes intermittently with Il2CppExceptionWrapper inside FirebaseAppCheck.TokenChangedMethod (the [MonoPInvokeCallback] for App Check token changes). The managed exception cannot propagate through the reverse P/Invoke boundary, so IL2CPP calls std::terminate and the app is killed.
We believe the cause is that AppCheckToken.expire_time_millis is never initialized in the iOS token-change notification path:
app_check/src/ios/app_check_ios.mm(firebase-cpp-sdk, same code in v13.11.0 and v14.1.0),appCheckTokenDidChangeNotification:creates a localfirebase::app_check::AppCheckToken cpp_token;and only setscpp_token.token. The TODO there (b/263138261) notes the notification does not contain an expiration time.AppCheckTokendeclaresint64_t expire_time_millis;without a default member initializer (app_check/src/include/firebase/app_check.h), so the field holds an indeterminate value.SwigAppCheckListener::OnAppCheckTokenChanged(app_check/src/swig/app_check.i) copies the token as-is and queuesCallbackValue1String1<AppCheckToken>to call into C#.FirebaseAppCheck.TokenChangedMethodcallsAppCheckToken.FromAppCheckTokenInternal, which runss_unixEpoch.AddMilliseconds((double)tokenInternal.expire_time_millis). When the indeterminate value falls outside the range ofDateTime(roughly -6.2e13 to +2.5e14 ms from the Unix epoch),AddMillisecondsthrowsArgumentOutOfRangeException. This happens before any user handler is called, and nothing catches it, so the app crashes.
This explains why the crash is intermittent: it depends on whatever value happens to be in that memory.
Note: the crash report does not include the managed exception type or message, so ArgumentOutOfRangeException is our inference from reading the source. We have not reproduced the crash locally.
Expected: a token-change notification should never crash the app. Possible fixes we can think of:
- Initialize
expire_time_millis(for exampleint64_t expire_time_millis = 0;), or set it explicitly inappCheckTokenDidChangeNotification:. - Guard the conversion in
FromAppCheckTokenInternal, and/or catch exceptions insideTokenChangedMethodso that nothing escapes the reverse P/Invoke callback.
Because the exception is thrown before the user's TokenChanged handler runs, we cannot work around it in app code other than by not subscribing to TokenChanged on iOS.
Reproducing the issue
We cannot reproduce it deterministically, because it depends on uninitialized memory.
- On iOS (IL2CPP), set an App Check provider factory (
AppAttestProviderFactoryin production) before initializing Firebase. - Get
FirebaseAppCheck.DefaultInstance, callSetTokenAutoRefreshEnabled(true), and subscribe toTokenChanged. - Call
GetAppCheckTokenAsync(false)at startup and keep the app running so that tokens are refreshed. - Occasionally the app crashes in
TokenChangedMethodwhen a token-change notification is delivered.
Firebase Unity SDK Version
13.15.0
Unity editor version
6000.0.58f2
Installation Method
Unity Package Manager
Problematic Firebase Component(s)
App Check
Other Firebase Component(s) in use
Analytics, Authentication, Crashlytics, Messaging
Additional SDKs you are using
YetAnotherHttpHandler (Rust native library), UniTask
Targeted Platform(s)
Apple Platforms
Unity editor platform
Mac
Scripting Runtime
IL2CPP
Release Distribution Type
Pre-built SDK from https://firebase.google.com/download/unity
Relevant Log Output
Fatal Exception: Il2CppExceptionWrapper
Crashed: com.google.firebase.crashlytics.ios.exception
7 UnityFramework FIRCLSTerminateHandler() + 426 (FIRCLSException.mm:426)
8 libc++abi.dylib std::__terminate(void (*)()) + 20
9 libc++abi.dylib __cxa_get_exception_ptr + 34
10 libc++abi.dylib __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*) + 138
11 UnityFramework il2cpp::vm::Exception::Rethrow(Il2CppException*) + 116 (Exception.cpp:116)
12 UnityFramework il2cpp_codegen_get_generic_virtual_method_internal(MethodInfo const*, MethodInfo const*) + 317
13-15 (mis-symbolicated as core::panicking::panic_fmt from a linked Rust library)
16 LivlyIsland ReversePInvokeWrapper.FirebaseAppCheck_TokenChangedMethod (Firebase.AppCheck.cpp)
17 UnityFramework firebase::callback::CallbackValue1String1<firebase::app_check::AppCheckToken>::Run() + 3496
18 UnityFramework firebase::callback::CallbackEntry::Execute() + 1564
19 UnityFramework firebase::callback::CallbackDispatcher::DispatchCallbacks() + 300
20 UnityFramework firebase::callback::PollCallbacks() + 48
21-22 (mis-symbolicated as core::panicking::panic_fmt)
23 UnityFramework il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**) + 624
27 UnityFramework MonoBehaviour::CallUpdateMethod(int) + 598If using CocoaPods for Apple platforms, the project's Podfile.lock
Not attached. Firebase Unity SDK 13.15.0, which targets Firebase iOS pod 12.17.0 (FIREBASE_IOS_POD_VERSION in cmake/firebase_unity_version.cmake).
Activity
niccolo-hare commentedon Oct 30, 2026
Hi @ccn-suzuki-naritada, thanks for reaching out. I did some testing, but I'm also unable to reproduce the issue with my sample project. Though, I believe there have been some recent changes with code related to time or timestamps used by the Firebase Unity SDKs, and I'm thinking some of these improvements might be able to resolve the issue. With that, could you try updating your Firebase SDKs to the latest version, then check if that helps mitigate the crash? This will also help us rule out issues related to outdated code.
Let me know how it goes.
ccn-suzuki-naritada commentedon Nov 6, 2026
Hi @niccolo-hare, thanks for looking into this.
As you suggested, we updated to the latest Firebase Unity SDK (14.1.0, together with EDM4U 1.2.190 so that the iOS SDK is resolved via Swift Package Manager) and ran a QA pass on iOS. Unfortunately, the crash still reproduces on 14.1.0, with the same stack trace as before:
This is consistent with the source: the code path from our original report is unchanged in 14.1.0.
app_check/src/ios/app_check_ios.mm:appCheckTokenDidChangeNotification:still createsfirebase::app_check::AppCheckToken cpp_token;and sets onlycpp_token.token.app_check/src/include/firebase/app_check.h:int64_t expire_time_millis;still has no initializer.AppCheckToken.FromAppCheckTokenInternalstill callss_unixEpoch.AddMilliseconds((double)tokenInternal.expire_time_millis)without a range check, andTokenChangedMethoddoes not catch exceptions.So we don't think the recent time/timestamp changes cover this path.
Since the crash depends on whatever value is left in uninitialized memory, it may not show up in a small sample project. You should be able to confirm the root cause without a crash by setting a breakpoint after
cpp_token.token = ...inappCheckTokenDidChangeNotification:and checking thatcpp_token.expire_time_millisholds an arbitrary value.This crash is having a serious impact on us. In our production app (still on 13.15.0), more than 3,300 iOS users have experienced it in the last 3 days. Because the exception is thrown inside the SDK before our
TokenChangedhandler is called, we cannot catch it in app code. The only workaround we have found is to stop subscribing toTokenChangedon iOS, which also means we no longer receive auto-refreshed tokens.We would really appreciate it if you could prioritize a fix. Could you let us know:
TokenChangedon iOS and callGetAppCheckTokenAsync(false)before each request instead?We are happy to provide more information if needed.
niccolo-hare commentedon Nov 6, 2026
Hi @ccn-suzuki-naritada, thanks for confirming and I'm sorry to hear that the issue persists. Regarding your questions, I think your example workaround would be safe to use for now. But let me raise these details to our engineers for further insights and to help expedite a solution if necessary.
I'll update you here once I have more information to share, or if I have additional questions.
fix(app_check): populate iOS TokenChanged expiration from JWT exp claim
niccolo-hare commentedon Nov 9, 2026
Hi @ccn-suzuki-naritada, just wanted to share an update regarding your questions:
expire_time_millisseems to be the source of the issue. Since it's uninitialized, it does appear to turn into a garbage value.GetAppCheckTokenAsync(false)on each request. This will help ensure you're passing a valid token as it returns a cached one and refreshes it when needed. Doing so shouldn't produce the crash since the call populatesexpire_time_milliswith the correct expiration time.Regarding the fix, we're working on an improvement to help mitigate this crash. But I am unable to provide you with a specific timeline or schedule on when it would be released. I would suggest checking out the Firebase Unity SDK release notes for more updates.
Let me know if you have additional questions or clarifications.
ccn-suzuki-naritada commentedon Nov 10, 2026
Hi @niccolo-hare, thank you for checking with your engineers and for the detailed update.
It's very helpful to have the root cause confirmed, and we really appreciate that you're working on a fix for this crash.
Since we pass the App Check token to our own backend, your note about calling
GetAppCheckTokenAsync(false)on each request is especially useful. Based on the information you shared, we'll discuss within our project how to apply this workaround on iOS. We'll also keep an eye on the release notes for the fix.Thanks again for your help.
fix(app_check): populate iOS TokenChanged expiration from JWT exp claim
[AppCheck] Populate iOS TokenChanged expiration from the JWT exp claim (
AustinBenoit commentedon Nov 11, 2026
Hi all,
The fix has been merged into the C++ repository. So we should expect this issue to be resolved in the next release. I'll post here again once we have the fixed version published.
Thanks all,
--Austin
AustinBenoit commentedon Nov 20, 2026
Hi @ccn-suzuki-naritada,
This fix is now published in Firebase Unity SDK v14.2.0 (via Firebase C++ SDK v14.2.0 / firebase/firebase-cpp-sdk#1961).
AppCheckToken::expire_time_millisis now default-initialized to0, and iOSTokenChangednotifications populate it from the JWTexpclaim (falling back to0if absent or out of range), resolving theArgumentOutOfRangeExceptioncrash inFirebaseAppCheck.TokenChangedMethod.Closing this issue now — please upgrade to v14.2.0 and let us know if you still run into any problems!
Thanks,
--Austin