From 25faf69491fe811fb3450be7f9ed7a7bacb38b92 Mon Sep 17 00:00:00 2001 From: Adem Ocel Date: Wed, 18 Nov 2026 15:01:14 +0300 Subject: [PATCH 1/3] feat(app_check): allow Swift Package Manager builds without the reCAPTCHA Enterprise SDK The iOS Swift package always adds recaptcha-enterprise-mobile-sdk, so every SPM app embeds the closed-source RecaptchaEnterpriseSDK framework even when it activates App Attest, DeviceCheck or the debug provider. The podspec has never added it. Setting FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA when building leaves the package and product out, like FIREBASE_ANALYTICS_WITHOUT_ADID does for firebase_analytics. The default is unchanged. Without the SDK, RecaptchaProvider(app:siteKey:) raises an Objective-C exception, which also happens today on CocoaPods when the app does not add the RecaptchaEnterprise pod. The "recaptcha" case now checks for the class the Firebase SDK uses to detect the SDK and leaves the provider unset with a log message instead. --- AUTHORS | 1 + docs/app-check/default-providers.md | 18 +++++++++++ .../ios/firebase_app_check/Package.swift | 30 ++++++++++++++----- .../FirebaseAppCheckPlugin.swift | 13 ++++++-- .../lib/src/apple_providers.dart | 6 ++++ 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0c0e6b091146..a6cda4c88b9f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -71,3 +71,4 @@ kfurue Max Wojczuk Julian Pscheid Artem Shevchenko +Adem Ocel diff --git a/docs/app-check/default-providers.md b/docs/app-check/default-providers.md index 0b844789d574..0f382a643ed5 100644 --- a/docs/app-check/default-providers.md +++ b/docs/app-check/default-providers.md @@ -132,6 +132,24 @@ This limitation is easiest to miss on a simulator, where the Apple SDK already defaults to the debug provider. See [flutterfire#18613](https://github.com/firebase/flutterfire/issues/18613). +### Leaving out the reCAPTCHA Enterprise SDK on iOS {:#without-recaptcha} + +With Swift Package Manager, the iOS plugin adds the +[reCAPTCHA Enterprise SDK](https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk) +so that `AppleReCaptchaProvider` works without extra setup. If your app uses +another Apple provider, set the `FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA` +environment variable when building to leave the SDK out of the app: + +```bash +FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true flutter build ios +``` + +You can also add this variable to your Xcode scheme's environment variables +for persistent configuration. With CocoaPods, the plugin does not add the SDK; +to use `AppleReCaptchaProvider`, add `pod 'RecaptchaEnterprise'` to your app's +`Podfile`. Without the SDK, `AppleReCaptchaProvider` configures no provider +and App Check token requests fail. + ## Next steps Once the App Check library is installed in your app, start distributing the diff --git a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Package.swift b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Package.swift index 975bc45cf49b..16e4e5112a2c 100644 --- a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Package.swift +++ b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Package.swift @@ -5,10 +5,31 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import Foundation import PackageDescription let firebaseSdkVersion: Version = "13.2.0" +// Set FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true to leave out the reCAPTCHA +// Enterprise SDK if the app does not use AppleReCaptchaProvider. +// e.g. FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true flutter build ios +let withoutRecaptcha = + ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] != nil + +var recaptchaPackages: [Package.Dependency] = [] +var recaptchaProducts: [Target.Dependency] = [] +if !withoutRecaptcha { + recaptchaPackages.append( + .package( + url: "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk.git", + from: "18.0.0" + ) + ) + recaptchaProducts.append( + .product(name: "RecaptchaEnterprise", package: "recaptcha-enterprise-mobile-sdk") + ) +} + let package = Package( name: "firebase_app_check", platforms: [ @@ -19,22 +40,17 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/firebase/firebase-ios-sdk", exact: firebaseSdkVersion), - .package( - url: "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk.git", - from: "18.0.0" - ), .package(name: "firebase_core", path: "../firebase_core"), .package(name: "FlutterFramework", path: "../FlutterFramework"), - ], + ] + recaptchaPackages, targets: [ .target( name: "firebase_app_check", dependencies: [ .product(name: "FirebaseAppCheck", package: "firebase-ios-sdk"), - .product(name: "RecaptchaEnterprise", package: "recaptcha-enterprise-mobile-sdk"), .product(name: "firebase-core", package: "firebase_core"), .product(name: "FlutterFramework", package: "FlutterFramework"), - ], + ] + recaptchaProducts, resources: [ .process("Resources") ] diff --git a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/FirebaseAppCheckPlugin.swift b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/FirebaseAppCheckPlugin.swift index 390f308e2033..f6af9a37e1eb 100644 --- a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/FirebaseAppCheckPlugin.swift +++ b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/FirebaseAppCheckPlugin.swift @@ -400,12 +400,21 @@ class AppCheckProviderWrapper: NSObject, AppCheckProvider { delegateProvider = appAttestProvider ?? DeviceCheckProvider(app: app) case "recaptcha": #if os(iOS) - if let recaptchaSiteKey { + // The reCAPTCHA Enterprise SDK can be left out of the build (CocoaPods, + // or FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA with Swift Package Manager). + // RecaptchaProvider then raises an Objective-C exception, so look up the + // class the Firebase SDK uses to detect it first. + let recaptchaLinked = NSClassFromString("RecaptchaEnterprise.RCARecaptcha") != nil + if recaptchaLinked, let recaptchaSiteKey { delegateProvider = RecaptchaProvider(app: app, siteKey: recaptchaSiteKey) } else { delegateProvider = nil } - if delegateProvider == nil { + if !recaptchaLinked { + print( + "Firebase App Check: failed to initialize RecaptchaProvider. Link the reCAPTCHA Enterprise SDK." + ) + } else if delegateProvider == nil { print( "Firebase App Check: failed to initialize RecaptchaProvider. Ensure site key is provided." ) diff --git a/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/apple_providers.dart b/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/apple_providers.dart index a84679abd2e9..500fd2833f7b 100644 --- a/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/apple_providers.dart +++ b/packages/firebase_app_check/firebase_app_check_platform_interface/lib/src/apple_providers.dart @@ -56,6 +56,12 @@ class AppleAppAttestWithDeviceCheckFallbackProvider } /// reCAPTCHA provider for Apple platforms. +/// +/// Only available on iOS, and only if the app links the reCAPTCHA Enterprise +/// SDK: Swift Package Manager builds add it unless +/// `FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA` is set; CocoaPods builds need the +/// `RecaptchaEnterprise` pod in the app's `Podfile`. Without the SDK, no +/// provider is configured and token requests fail. class AppleReCaptchaProvider extends AppleAppCheckProvider { /// Creates an Apple reCAPTCHA provider with a required [siteKey]. const AppleReCaptchaProvider(this.siteKey) : super('recaptcha'); From c789e208f1fa8ee9a3fa2171ae99f6088752b524 Mon Sep 17 00:00:00 2001 From: Adem Ocel Date: Wed, 18 Nov 2026 16:34:32 +0300 Subject: [PATCH 2/3] style(app_check): use a doc comment for the reCAPTCHA opt-out in Package.swift swiftformat (melos format-ci) flags the plain comment above withoutRecaptcha under its docComments rule. swift-format, which the CI format job runs, accepts both. --- .../firebase_app_check/ios/firebase_app_check/Package.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Package.swift b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Package.swift index 16e4e5112a2c..fe613208bf7e 100644 --- a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Package.swift +++ b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Package.swift @@ -10,9 +10,9 @@ import PackageDescription let firebaseSdkVersion: Version = "13.2.0" -// Set FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true to leave out the reCAPTCHA -// Enterprise SDK if the app does not use AppleReCaptchaProvider. -// e.g. FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true flutter build ios +/// Set FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true to leave out the reCAPTCHA +/// Enterprise SDK if the app does not use AppleReCaptchaProvider. +/// e.g. FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true flutter build ios let withoutRecaptcha = ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] != nil From f04a09afd96f01a266f2c28ba4763c53f8491dda Mon Sep 17 00:00:00 2001 From: Adem Ocel Date: Wed, 18 Nov 2026 17:19:27 +0300 Subject: [PATCH 3/3] chore: add contact email to AUTHORS entry --- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index a6cda4c88b9f..952d45c379b0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -71,4 +71,4 @@ kfurue Max Wojczuk Julian Pscheid Artem Shevchenko -Adem Ocel +Adem Ocel