簡體   English   中英

應用程序檢查 Firebase 可調用函數上不需要的強制執行

[英]App check unwanted enforcement on Firebase callable functions

沒有更改我的 Firebase 可調用函數代碼中的任何內容,而是重新部署它們,現在它們突然開始拒絕來自我的應用程序的所有 function 調用,錯誤如下所示。 在我准備好進行所需的更改之前,我不想使用 App Check。 如何阻止我的可調用 (https.onCall) Firebase 函數拒絕無效的應用程序檢查,而只拒絕無效的身份驗證?

Failed to validate AppCheck token. FirebaseAppCheckError: Decoding App Check token failed. Make sure you passed the entire string JWT which represents the Firebase App Check token.
    at FirebaseAppCheckError.FirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:44:28)
    at FirebaseAppCheckError.PrefixedFirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:90:28)
    at new FirebaseAppCheckError (/workspace/node_modules/firebase-admin/lib/app-check/app-check-api-client-internal.js:187:28)
    at /workspace/node_modules/firebase-admin/lib/app-check/token-verifier.js:82:19
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  errorInfo: {
    code: 'app-check/invalid-argument',
    message: 'Decoding App Check token failed. Make sure you passed the entire string JWT which represents the Firebase App Check token.'
  },
  codePrefix: 'app-check'
} 

Callable request verification failed: AppCheck token was rejected. {"verifications":{"app":"INVALID","auth":"VALID"}}

由於 App Check 無效而拒絕所有請求的代碼非常簡單:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.example = functions.https.onCall((data, context) => {
  return "test";
}

Package.json:

"engines": {
    "node": "12"
},
"main": "index.js",
"dependencies": {
  "firebase-admin": "^9.10.0",
  "firebase-functions": "^3.14.1"
},

來自https.onCall的協議規范:

可選 [Header]:X-Firebase-AppCheck:發出請求的客戶端應用程序提供的 Firebase App Check 令牌。 后端自動驗證此令牌並對其進行解碼,將 appId 注入處理程序的上下文中。 如果無法驗證令牌,則請求被拒絕。 (適用於 SDK >=3.14.0)

我的猜測是對您的可調用 function 的調用包含無效的 App Check 令牌。

如果您尚未在您的項目上配置 DeviceCheck 或/和 App Attest 證明提供程序,但已在您的客戶端中包含 App Check 庫,則您的客戶端代碼可能會在調用您的 function 時包含一個虛擬 App Check 令牌(有關此github 問題的完整詳細信息).

Firebase 團隊正在努力通過更改來減少體驗的混亂。 請在http://github.com/firebase/firebase-functions/issues/967https://github.com/FirebaseExtended/flutterfire/issues/6794中關注狀態。

我有同樣的經歷。 文檔說你應該像這樣檢查[1]:

  if (context.app == undefined) {
    throw new functions.https.HttpsError(
        'failed-precondition',
        'The function must be called from an App Check verified app.')
  }

但是,根據我的經驗,情況並非如此,當您將 App Check 添加到您的應用程序時,App Check 會立即開始執行。

[1] 來源https://firebase.google.com/docs/app-check/cloud-functions

當我在模擬器上運行應用程序時,我的問題是一樣的,在真實設備上運行后運行沒有任何問題。 這就是發生在我身上的事情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM