Description
Summary
Using latest Firebase v9.12 (through latest AngularFire 7.4.1) in production, with AppCheck, Firestore, and Auth.
When leaving the webapp tab open and idle, the app often runs into a 403
error in POST request to exchange AppCheck token ("App attestation failed." "PERMISSION DENIED"), followed by a warning: @firebase/app-check: AppCheck: Requests throttled due to 403 error. Attempts allowed again after 01d:00m:00s (appCheck/throttled).
Console Tab
As you can see, the appCheck/throttled
warning shows up twice, and is preceded by a failing 403 POST request to content-firebaseappcheck.googleapis.com/...exchangeRecaptchaV3Token
There was no exponential backoff. Quoting from @hsubox76 in #6373 (comment):
403 errors are throttled for 1 day because it is likely there's something wrong with the attestation that won't be fixed with a simple retry, such as a bad API key or an attestation failure due to failing ReCAPTCHA. You can see the code for the throttling here (this also applies to 404):
After the failed token exchange & AppCheck throttling, Firestore can no longer load data, thus logging several "FirebaseError: Missing or insufficient permissions.
" on all active document/collection listeners, rendering the app dysfunctional.
In a second tab running the same app, a similar crash was observed, but it was preceded by a Timeout
error in recaptcha__en.js
and a @firebase/app-check: FirebaseError: AppCheck: ReCAPTCHA error. (appCheck/recaptcha-error).
Network Tab
As you can see from the network tab, the 403 POST request failed with "App attestation failed." - when is this supposed to occur?
There were no further requests to firebaseappcheck.googleapis.com, but there was a successful OPTIONS
request 200
at the same second Wed, 19 Oct 2022 10:17:35 GMT
:
Right before the failing 403 request, during the same second 10:17:35 GMT, there was a POST request to Firestore with query parameter TYPE=terminate
- could this be related? Sounds suspicious.
There were no further requests to firebaseappcheck.googleapis.com but there were successful token requests to securetoken.googleapis.com/v1/token
every 55 minutes before & after the 403 issue:
09:07:52 GMT
10:02:53 GMT
10:57:54 GMT
11:52:55 GMT
12:47:56 GMT
Reproduction
The issue is tricky to reproduce, as it's related to token expiration. I often leave the tab open for several days before it happens.
Today I encountered this issue during the workday, while the computer was on all the time, in two different tabs that were open in the background. The same behavior mentioned above was observed in both tabs, 4 seconds apart:
Wed, 19 Oct 2022 10:17:35 GMT
Wed, 19 Oct 2022 10:17:39 GMT
These 4 seconds could be the difference from when I initially opened or interacted with each tab, hinting at a token expiration issue timeout, possibly initiated by Firestore terminate.