Repository navigation
Conversation
…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.
|
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. |
There was a problem hiding this comment.
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".
| let withoutRecaptcha = | ||
| ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] != nil |
There was a problem hiding this comment.
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".
| let withoutRecaptcha = | |
| ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] != nil | |
| let withoutRecaptcha = | |
| ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] == "true" |
…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.
|
@googlebot I signed it! |
Description
The iOS
Package.swiftoffirebase_app_checkhas depended onrecaptcha-enterprise-mobile-sdkunconditionally since #18261. With Swift Package Manager,every iOS app using the plugin therefore embeds the prebuilt, closed-source
RecaptchaEnterpriseSDK.frameworkinRunner.app/Frameworks, even if it only activatesApp 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_ADIDinfirebase_analytics:When the variable is set,
Package.swiftleaves out therecaptcha-enterprise-mobile-sdkpackage and the
RecaptchaEnterpriseproduct. If it is not set, the dependency graph staysthe same as before.
Leaving the SDK out exposes a crash that CocoaPods apps can already hit:
RecaptchaProvider(app:siteKey:)raises an Objective-CNSInternalInconsistencyExceptionwhen the reCAPTCHA Enterprise SDK is not linked (
FIRRecaptchaProvider.m, "The reCAPTCHAEnterprise SDK is not linked"). Swift cannot catch it, so the app crashes in
configure.Before it builds the provider, the
"recaptcha"case inFirebaseAppCheckPlugin.swiftnowchecks 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 notconfigured" 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 addedunless
FIREBASE_APP_CHECK_WITHOUT_RECAPTCHAis set.ios/.../FirebaseAppCheckPlugin.swift(macOS uses the same file through a symlink; thecase only compiles on iOS): runtime check before
RecaptchaProvideris created.AppleReCaptchaProviderdoc comment anddocs/app-check/default-providers.md: how toleave the SDK out with SPM, and that CocoaPods apps need the
RecaptchaEnterprisepodto use the reCAPTCHA provider.
Related Issues
Enterprise SDK.
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.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.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_checkexample app, afterflutter clean(
flutter build ios --release --no-codesignfor the bundle contents, and a simulator debugrun with a temporary, uncommitted entrypoint for the runtime check). The variable reaches
SPM resolution through the environment of
flutter build;swift package dump-packagelists four dependencies without it and three with it:
Runner.app/Frameworks/RecaptchaEnterpriseSDK.frameworkispresent, as before;
FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true: no*recaptcha*file inRunner.app;FIRAppAttestProvideris still linked;AppleReCaptchaProvider: no crash; the log says the SDK is notlinked and
getTokenthrowsFirebaseException(firebase_app_check/unknown).Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
The default build is unchanged. Only apps that set the new variable lose the SDK.