모바일 또는 웹 앱에서 직접 API를 호출하면 (예: 생성형 AI 모델에 대한 액세스를 허용하는 API) 승인되지 않은 클라이언트가 API를 악용할 수 있습니다. 이러한 API를 보호하려면 Firebase App Check를 사용하여 모든 수신 API 호출이 실제 앱에서 이루어지는지 확인할 수 있습니다.
Firebase AI Logic는 Firebase App Check와 통합하고 모바일 및 웹 앱에서 호출하는 생성형 AI 모델 API를 보호할 수 있는 프록시 게이트웨이를 제공합니다. Firebase AI Logic SDK와 함께 App Check을 사용하면 모든 구성을 지원합니다.
'Gemini API' 제공업체인 Gemini Developer API와 Vertex AI Gemini API를 모두 보호합니다.
Gemini 모델과 Imagen 모델 모두 지원되는 모든 모델을 보호합니다.
App Check 작동 방식에 대한 간략한 요약
App Check를 사용하면 앱을 실행하는 기기는 다음 중 하나 또는 둘 모두를 확인하는 앱 또는 기기 증명 제공자를 사용합니다.
요청이 인증된 앱에서 발생함
요청이 변조되지 않은 인증된 기기에서 발생함
이 증명은 앱이 Firebase AI Logic SDK를 사용하여 수행하는 모든 요청에 연결됩니다. App Check 적용을 사용 설정하면 유효한 증명이 없는 클라이언트의 요청이 거부되며 승인하지 않은 앱이나 플랫폼에서 발생한 요청도 거부됩니다.
App Check를 설정할 때는 향상된 보호 기능(재생 보호라고 함)을 준비하는 것이 좋습니다.
Gemini API 제공업체를 클릭하여 이 페이지에서 제공업체별 콘텐츠와 코드를 확인합니다.
Flutter 앱에서 Firebase AI Logic와 함께 App Check를 사용하는 경우 인스턴스화 중에 App Check를 명시적으로 전달해야 합니다.
// ...finalai=awaitFirebaseAI.googleAI(appCheck:FirebaseAppCheck.instance,// for Flutter, pass in App Check explicitly);// ...
향상된 보호 기능에 대비하기
제한된 사용 토큰 사용 설정은 Apple 플랫폼 (v12.2.0 이상), Android (v17.2.0 이상, BoM v34.2.0 이상), 웹 (v12.3.0 이상), Flutter (v3.2.0 이상, BoM v4.2.0 이상)에서 지원됩니다.
Unity 지원은 곧 제공될 예정입니다.
기본적으로 App Check는 30분과 7일 사이에 구성 가능한 TTL (수명)이 있는 세션 토큰을 사용합니다.
이러한 세션 토큰은 App Check SDK에 의해 캐시되고 앱의 요청과 함께 전송됩니다.
향후 App Check에서는 Firebase AI Logic에 재생 보호를 사용 설정하는 옵션을 추가할 예정입니다 (App Check에서 이미 일부 다른 리소스에 제공하는 지원과 유사). 재생 보호를 사용 설정하면 다음과 같은 방식으로 보호가 강화됩니다.
App Check는 제한된 사용 토큰이라는 특별한 종류의 토큰이 함께 제공되는 요청만 허용합니다.
제한된 사용 토큰이 확인되면 토큰이 소비되어 한 번만 사용할 수 있으므로 재생 공격이 방지됩니다.
재생 보호를 준비하려면 App Check 설정의 일환으로 사용이 제한된 토큰의 사용을 사용 설정하는 것이 좋습니다. 이렇게 하면 리플레이 보호가 제공될 때 더 많은 사용자가 제한된 사용 토큰을 전송하는 앱 버전을 사용하므로 더 빨리 사용 설정할 수 있습니다.
지금 앱에서 사용 빈도가 제한된 토큰 사용을 사용 설정하는 경우(재생 보호를 사용할 수 없는 경우) 다음 사항에 유의하세요.
App Check는 유효한 세션 토큰의 사용을 차단하지 않습니다.
세션 토큰과 마찬가지로 제한된 사용 토큰은 App Check SDK에 의해 캐시되고 요청과 함께 전송됩니다. 이러한 제한된 사용 토큰은 세션 토큰에 비해 TTL이 짧기 때문에(5분이며 조정할 수 없음) 기본 세션 토큰보다 약간 더 많은 보호를 제공합니다.
제한된 사용 토큰은 5분 동안 유효하지만 SDK는 각 요청에 대해 새 토큰을 생성합니다. 이 프로세스로 인해 요청에 지연 시간이 추가될 수 있습니다.
하지만 향후 Firebase AI Logic에서 재생 보호를 사용할 수 있게 되면 (사용 설정하는 경우) 세션 토큰을 사용하고 제한된 사용 토큰을 재사용할 수 없습니다. 각 요청에 대해 새 토큰을 생성하는 추가 지연 시간은 계속 발생합니다.
제한된 사용 토큰 사용 설정
Gemini API 제공업체를 클릭하여 이 페이지에서 제공업체별 콘텐츠와 코드를 확인합니다.
인스턴스화하는 동안 앱에서 useLimitedUseAppCheckTokens 매개변수를 true로 설정하여 사용 빈도가 제한된 토큰의 사용을 사용 설정합니다.
Swift
// ...// During instantiation, enable usage of limited-use tokensletai=FirebaseAI.firebaseAI(backend:.googleAI(),useLimitedUseAppCheckTokens:true)// ...
Kotlin
// ...// During instantiation, enable usage of limited-use tokensvalai=Firebase.ai(backend=GenerativeBackend.googleAI(),useLimitedUseAppCheckTokens=true)// ...
Java
// ...// During instantiation, enable usage of limited-use tokensFirebaseAIai=FirebaseAI.getInstance(/* backend: */GenerativeBackend.googleAI(),/* useLimitedUseAppCheckTokens: */true);// ...
Web
// ...// During instantiation, enable usage of limited-use tokensconstai=getAI(firebaseApp,{backend:newGoogleAIBackend(),useLimitedUseAppCheckTokens:true});// ...
Dart
// ...// During instantiation, enable usage of limited-use tokensfinalai=awaitFirebaseAI.googleAI(appCheck:FirebaseAppCheck.instance,// for Flutter, pass in App Check explicitlyuseLimitedUseAppCheckTokens:true,);// ...
Unity
Unity 게임에서 제한된 사용 토큰을 사용하는 기능은 향후 출시에서 지원될 예정입니다. 나중에 다시 확인해 주세요.
Firebase AI Logic이 App Check과 통합되는 방식 이해하기
Firebase AI Logic SDK를 사용하려면 Firebase 프로젝트에서 Firebase AI Logic API (firebasevertexai.googleapis.com)를 사용 설정해야 합니다. 이는 Firebase AI Logic SDK에서 전송된 요청이 먼저 Firebase AI Logic 서버로 전송되기 때문입니다. 이 서버는 요청이 선택한 'Gemini API' 제공업체의 백엔드와 Gemini 및 Imagen 모델에 액세스하는 API로 진행되기 전에 Firebase App Check 확인이 이루어지는 프록시 게이트웨이 역할을 합니다.
[null,null,["최종 업데이트: 2025-09-02(UTC)"],[],[],null,["\u003cbr /\u003e\n\nWhen you call an API directly from a mobile or web app (for example, the APIs\nthat allow access to generative AI models), the API is vulnerable to abuse by\nunauthorized clients. To help protect these APIs, you can use\n[Firebase App Check](/docs/app-check) to verify that all incoming API calls\nare from your actual app.\n\nFirebase AI Logic provides a proxy gateway that lets you integrate with\nFirebase App Check and protect the generative AI model APIs called by your\nmobile and web apps. Using App Check with the\nFirebase AI Logic SDKs supports all our configurations:\n\n- Protects both \"Gemini API\" providers: Gemini Developer API and\n Vertex AI Gemini API.\n\n- Protects all supported models, both Gemini models and Imagen\n models.\n\n| We **strongly recommend implementing\n| Firebase App Check into your app as early as possible**, even during development, so that every version of your app is protected from API abuse.\n\nHigh-level summary of how App Check works\n\nWith App Check, devices running your app use an app or device attestation\nprovider that verifies one or both of the following:\n\n- Requests originate from your authentic app\n- Requests originate from an authentic, untampered device\n\nThis attestation is attached to every request your app makes using a\nFirebase AI Logic SDK. When you enable App Check enforcement,\nrequests from clients without a valid attestation will be rejected, as will any\nrequest originating from an app or platform you haven't authorized.\n\nWe recommend that when you set up App Check, make sure to\n[prepare for upcoming enhanced protection](#enhanced-protection)\n(known as *replay protection*).\n\nYou can find [detailed information about App Check](/docs/app-check) in its\ndocumentation, including its [quotas and limits](/docs/app-check#quotas_limits).\n\nAvailable providers and implementation instructions\n\nThe App Check documentation provides descriptions of attestation providers\nas well as implementation instructions.\n\n1. Choose a default provider, and follow the implementation instructions at the\n following links:\n\n - **Apple platforms** : [DeviceCheck](/docs/app-check/ios/devicecheck-provider) or [App Attest](/docs/app-check/ios/app-attest-provider)\n - **Android** : [Play Integrity](/docs/app-check/android/play-integrity-provider)\n - **Web** : [reCAPTCHA Enterprise](/docs/app-check/web/recaptcha-enterprise-provider)\n - **Flutter** : Supports [all the default providers above](/docs/app-check/flutter/default-providers) \n Also, make sure to follow [special instantiation requirements](#instantiation-flutter) for Flutter and App Check.\n - **Unity** : Supports [all the default providers above](/docs/app-check/unity/default-providers)\n\n Note that if none of the default providers are sufficient for your needs,\n then you can [implement a custom provider](/docs/app-check/custom-provider)\n that uses either a third-party attestation provider or your own attestation\n techniques.\n2. *(Recommended)*\n [Prepare for upcoming enhanced protection from App Check](#enhanced-protection)\n (known as *replay protection*).\n\n3. *(Required)* Before you release your app to real users,\n [**enable enforcement of App Check**](/docs/app-check/enable-enforcement).\n\nSpecial instantiation required for Flutter\n\n|-------------------------------------------------------------------------------------------------------------------------------------|\n| *Click your Gemini API provider to view provider-specific content and code on this page.* Gemini Developer API Vertex AI Gemini API |\n\nWhen using App Check with Firebase AI Logic in Flutter apps, you need to\nexplicitly pass in App Check during instantiation, like so: \n\n // ...\n\n final ai = await FirebaseAI.googleAI(\n appCheck: FirebaseAppCheck.instance, // for Flutter, pass in App Check explicitly\n );\n\n // ...\n\nPrepare for upcoming enhanced protection\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ***Enabling the usage of limited-use tokens is supported for Apple platforms (v12.2.0+), Android (v17.2.0+, BoM v34.2.0+), Web (v12.3.0+), and Flutter (v3.2.0+, BoM v4.2.0+).** Support for Unity is coming soon.* |\n\nBy default, App Check uses *session tokens* which have a configurable\ntime to live (TTL) between 30 minutes and 7 days.\nThese session tokens are cached by the App Check SDK and sent along with\nrequests from your app.\n\nIn the future, App Check will add the option to enable *replay protection*\nfor Firebase AI Logic (similar to the support that App Check already\noffers for some other resources). When replay protection is enabled, it\nenhances protection in the following ways:\n\n- App Check will only allow requests if they're accompanied by a special\n kind of token called a *limited-use token*.\n\n- After the limited-use token is verified, the token is consumed so that it can\n be used only once, preventing replay attacks.\n\n**To prepare for replay protection, we recommend that you\n[enable the usage of limited-use tokens](#enable-limited-use-tokens)** as part\nof setting up App Check. That way, when replay protection becomes available,\nthen you can enable it sooner because more of your users will be on versions\nof your app that send limited-use tokens.\n\nNote the following if you enable usage of limited-use tokens in your app now\n(while replay protection is unavailable):\n\n- App Check does *not* block the usage of *valid session tokens*.\n\n- Just like session tokens, limited-use tokens are cached by the\n App Check SDK and sent along with requests. These limited-use tokens\n provide a *small* amount of additional protection than the default session\n tokens because limited-use tokens have a shorter TTL\n (only 5 minutes and not adjustable) compared to session tokens.\n\n- Even though limited-use tokens are valid for 5 minutes, the SDK\n will still generate a new token for *each* request. This process can add some\n latency to your request.\n\nHowever, when replay protection is available for Firebase AI Logic in the\nfuture (and you enable it), the use of session tokens and the reuse of\nlimited-use tokens won't be possible. Note that the additional latency for\ngenerating a new token for each request will still happen.\n\nEnable usage of limited-use tokens\n\n|-------------------------------------------------------------------------------------------------------------------------------------|\n| *Click your Gemini API provider to view provider-specific content and code on this page.* Gemini Developer API Vertex AI Gemini API |\n\n| **Note:** Consider setting up limited-use tokens to be a Firebase Remote Config parameter so that you can control its setting remotely rather than having it hard-coded in your app. Learn more about [using Remote Config](/docs/ai-logic/solutions/remote-config).\n\nHere's how to enable usage of limited-use tokens:\n\n1. [Implement App Check](#available-providers), and make sure that you've\n [enabled App Check enforcement](/docs/app-check/enable-enforcement)\n for your app.\n\n2. In your app during instantiation, enable the usage of limited-use tokens by\n setting the `useLimitedUseAppCheckTokens` parameter to `true`:\n\n Swift \n\n\n // ...\n\n // During instantiation, enable usage of limited-use tokens\n let ai = FirebaseAI.firebaseAI(\n backend: .googleAI(),\n useLimitedUseAppCheckTokens: true\n )\n\n // ...\n\n Kotlin \n\n\n // ...\n\n // During instantiation, enable usage of limited-use tokens\n val ai = Firebase.ai(\n backend = GenerativeBackend.googleAI(),\n useLimitedUseAppCheckTokens = true\n )\n\n // ...\n\n Java \n\n\n // ...\n\n // During instantiation, enable usage of limited-use tokens\n FirebaseAI ai = FirebaseAI.getInstance(\n /* backend: */ GenerativeBackend.googleAI(),\n /* useLimitedUseAppCheckTokens: */ true\n );\n\n // ...\n\n Web \n\n\n // ...\n\n // During instantiation, enable usage of limited-use tokens\n const ai = getAI(firebaseApp, {\n backend: new GoogleAIBackend(),\n useLimitedUseAppCheckTokens: true\n });\n\n // ...\n\n Dart \n\n\n // ...\n\n // During instantiation, enable usage of limited-use tokens\n final ai = await FirebaseAI.googleAI(\n appCheck: FirebaseAppCheck.instance, // for Flutter, pass in App Check explicitly\n useLimitedUseAppCheckTokens: true,\n );\n\n // ...\n\n Unity\n\n Using limited-use tokens with Unity games will be supported in a\n future release. Check back soon!\n\nUnderstand how Firebase AI Logic integrates with App Check\n\nTo use the Firebase AI Logic SDKs, the\n[Firebase AI Logic API (`firebasevertexai.googleapis.com`)](https://console.cloud.google.com/apis/library/firebasevertexai.googleapis.com?project=_)\nmust be enabled in your Firebase project. This is because requests made by the\nFirebase AI Logic SDKs are first sent to the Firebase AI Logic\nserver, which acts as a proxy gateway where Firebase App Check verification\ntakes place *before* the request is allowed to proceed to your chosen\n\"Gemini API\" provider's backend and the APIs to access the Gemini\nand Imagen models."]]