Skip to content

feat(app_check): allow Swift Package Manager builds without the reCAPTCHA Enterprise SDK - #18981

Open
moosyroot wants to merge 3 commits into
firebase:mainfrom
moosyroot:feat/app-check-spm-without-recaptcha
Open

moosyroot wants to merge 3 commits into
firebase:mainfrom
moosyroot:feat/app-check-spm-without-recaptcha

Conversation

@moosyroot

@moosyroot moosyroot commented Nov 18, 2026 •

Copy link
Copy Markdown

Description

The iOS Package.swift of firebase_app_check has depended on
recaptcha-enterprise-mobile-sdk unconditionally since #18261. With Swift Package Manager,
every iOS app using the plugin therefore embeds the prebuilt, closed-source
RecaptchaEnterpriseSDK.framework in Runner.app/Frameworks, even if it only activates
App Attest, DeviceCheck or the debug provider. The podspec does not add the SDK, so
CocoaPods apps do not ship it.

This PR adds a build-time opt-out that works like FIREBASE_ANALYTICS_WITHOUT_ADID in
firebase_analytics:

FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true flutter build ios

When the variable is set, Package.swift leaves out the recaptcha-enterprise-mobile-sdk
package and the RecaptchaEnterprise product. If it is not set, the dependency graph stays
the same as before.

Leaving the SDK out exposes a crash that CocoaPods apps can already hit:
RecaptchaProvider(app:siteKey:) raises an Objective-C NSInternalInconsistencyException
when the reCAPTCHA Enterprise SDK is not linked (FIRRecaptchaProvider.m, "The reCAPTCHA
Enterprise SDK is not linked"). Swift cannot catch it, so the app crashes in configure.
Before it builds the provider, the "recaptcha" case in FirebaseAppCheckPlugin.swift now
checks for RecaptchaEnterprise.RCARecaptcha, the class the Firebase SDK itself looks up
(AppCheckRecaptchaProvider.isSupported() in google/app-check). If the class is missing,
the plugin leaves the provider unset and logs a message, so token requests fail with a
FirebaseException (firebase_app_check/unknown; the SDK wraps its "Provider not
configured" error) instead of a crash. Apps that link the SDK still
get the same provider.

Changes:

  • ios/firebase_app_check/Package.swift: the reCAPTCHA package and product are added
    unless FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA is set.
  • ios/.../FirebaseAppCheckPlugin.swift (macOS uses the same file through a symlink; the
    case only compiles on iOS): runtime check before RecaptchaProvider is created.
  • AppleReCaptchaProvider doc comment and docs/app-check/default-providers.md: how to
    leave the SDK out with SPM, and that CocoaPods apps need the RecaptchaEnterprise pod
    to use the reCAPTCHA provider.

Related Issues

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Testing: the change is in the Swift package manifest and in a native branch that runs only
when the reCAPTCHA Enterprise SDK is missing, and Dart unit tests cannot reach either.
Verified on iOS with the firebase_app_check example app, after flutter clean
(flutter build ios --release --no-codesign for the bundle contents, and a simulator debug
run with a temporary, uncommitted entrypoint for the runtime check). The variable reaches
SPM resolution through the environment of flutter build; swift package dump-package
lists four dependencies without it and three with it:

  • without the variable: Runner.app/Frameworks/RecaptchaEnterpriseSDK.framework is
    present, as before;
  • with FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true: no *recaptcha* file in
    Runner.app; FIRAppAttestProvider is still linked;
  • with the variable and AppleReCaptchaProvider: no crash; the log says the SDK is not
    linked and getToken throws FirebaseException (firebase_app_check/unknown).

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

The default build is unchanged. Only apps that set the new variable lose the SDK.

…TCHA 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.
@google-cla

google-cla Bot commented Nov 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an option to exclude the reCAPTCHA Enterprise SDK from iOS builds when using Swift Package Manager by setting the FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA environment variable. It updates the documentation, dynamically checks for the presence of the reCAPTCHA class at runtime in the iOS plugin, and conditionally includes the dependency in Package.swift. The review feedback recommends refining the environment variable check in Package.swift to verify if it is explicitly set to "true" rather than just checking for its existence, which prevents issues if a user sets it to "false".

Comment on lines +16 to +17
let withoutRecaptcha =
ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] != nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Checking != nil on the environment variable means that if a user explicitly sets FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=false (for example, in their CI/CD environment or Xcode scheme to temporarily disable the opt-out), it will still evaluate to true because the environment variable exists.

It is safer and more robust to check if the value is explicitly "true".

Suggested change
let withoutRecaptcha =
ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] != nil
let withoutRecaptcha =
ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] == "true"

@moosyroot
moosyroot marked this pull request as draft November 18, 2026 12:46
…age.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.
@moosyroot

Copy link
Copy Markdown
Author

@googlebot I signed it!

@moosyroot
moosyroot marked this pull request as ready for review November 18, 2026 14:19

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[firebase_app_check]: iOS Swift package always embeds the closed-source reCAPTCHA Enterprise SDK, even when the app never uses AppleReCaptchaProvider

1 participant