[Bug] App Check (iOS): crash in TokenChangedMethod because AppCheckToken.expire_time_millis is left uninitialized
Maintainers usually reply within 1 day
@AustinBenoit is already working on this.
Since Nov 10, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp, objective-c
- Domain
- backend-api-design, mobile
Research direction
Start by tracing the iOS notification path in app_check/src/ios/app_check_ios.mm, the AppCheckToken declaration in app_check/src/include/firebase/app_check.h, and the conversion in FirebaseAppCheck.TokenChangedMethod. Check whether the token expiration field is initialized before the callback reaches C#. The report has no reproducer; done means token-change notifications no longer crash when expiration data is absent or invalid, with coverage for that case.
Written by the indexing model from the issue text.
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) + 598
If 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).
- Dominant language
- C#
- Stars
- 325
- Forks
- 62
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 13
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/firebase-unity-sdk
-
[Bug] Desktop managed DLLs marked Required32Bit fail to load on ARM64 CoreCLR (Unity 7 alpha)Possibly taken @AustinBenoit claimed this today. Openapi: core desktop production type: bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
firebase/firebase-unity-sdk#1566 · 1 comment ·
Maintainers usually reply within 1 day
-
api: core
Difficulty 4/5 3-5 days Newbie friendliness 43/100
firebase/firebase-unity-sdk#1562 · 1 comment ·
Maintainers usually reply within 1 day
-
api: crashlytics type: question
Difficulty 4/5 3-5 days Newbie friendliness 45/100
firebase/firebase-unity-sdk#1560 · 2 comments ·
Maintainers usually reply within 1 day
-
api: firestore type: feature request
Difficulty 5/5 Over a week Newbie friendliness 35/100
firebase/firebase-unity-sdk#1543 · 1 comment ·
Maintainers usually reply within 1 day
-
api: appcheck desktop production type: bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
firebase/firebase-unity-sdk#1530 · 3 comments ·
Maintainers usually reply within 1 day
All issues in firebase/firebase-unity-sdk
Similar issues
-
Support Flux ignore rules (drift detection ignore paths) in Microsoft.KubernetesConfiguration schemaOpen
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Azure/azure-resource-manager-schemas#3921 ·
Maintainers usually reply within 1 day
-
text-align: justify is ignored in HTML to PDF conversionPossibly taken @PrzemyslawKlys claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 4 days
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100