Skip to content

Check for non-Enterprise recaptcha object #6421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2022
Merged

Conversation

hsubox76
Copy link
Contributor

@hsubox76 hsubox76 commented Jul 7, 2022

Auth's ReCaptchaLoaderImpl.load() method checks for if the ReCAPTCHA script tag has already been loaded by itself or another library, and does not load it again if so. It does this by checking for the global object window.grecaptcha. Unfortunately, this object will exist if the ReCAPTCHA Enterprise version of the script has been loaded (which may be done by App Check if the user is using ReCAPTCHA Enterprise with App Check), BUT it will only contain the enterprise property, which is a nested version of the regular ReCAPTCHA object.

This change has the load() method check instead for the existence of window.grecaptcha.render. If it is not found, it will go ahead and load the non-Enterprise script tag, which seems to be able to co-exist with Enterprise and just adds the render/execute/etc methods onto the top level of the object without removing the enterprise property.

In the future, a more robust fix could be to extract a shared recaptcha loader to be used by Auth, App Check, and any other library that needs it.

One interesting note: the condition in shouldResolveImmediately() is kind of odd, in that it will always resolve if window.grecaptcha.render exists, regardless of the other 2 conditions, since this.librarySeparatelyLoaded is just also !!window.grecaptcha.render. But in the interest of a quick fix and breaking as little as possible, I will leave it be for now.

Fixes #6133

@changeset-bot
Copy link

changeset-bot bot commented Jul 7, 2022

⚠️ No Changeset found

Latest commit: 927d06b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@sam-gc sam-gc left a comment

Choose a reason for hiding this comment

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

Thanks!

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 7, 2022

Size Report 1

Affected Products

  • @firebase/auth

    TypeBase (a6dc377)Merge (68a809a)Diff
    browser155 kB155 kB+102 B (+0.1%)
    esm5203 kB203 kB+102 B (+0.1%)
    module155 kB155 kB+102 B (+0.1%)
    react-native168 kB168 kB+102 B (+0.1%)
  • @firebase/auth/internal

    TypeBase (a6dc377)Merge (68a809a)Diff
    browser166 kB166 kB+102 B (+0.1%)
    esm5216 kB216 kB+102 B (+0.0%)
    module166 kB166 kB+102 B (+0.1%)
  • @firebase/auth/react-native

    TypeBase (a6dc377)Merge (68a809a)Diff
    browser168 kB168 kB+102 B (+0.1%)
    module168 kB168 kB+102 B (+0.1%)
  • bundle

    TypeBase (a6dc377)Merge (68a809a)Diff
    auth (Phone)76.4 kB76.5 kB+94 B (+0.1%)
    firestore-lite (Query Cursors)210 kB67.9 kB-142 kB (-67.7%)
    firestore-lite (Query)210 kB71.1 kB-139 kB (-66.2%)
    firestore-lite (Read data once)200 kB55.5 kB-144 kB (-72.2%)
    firestore-lite (Transaction)184 kB80.1 kB-103 kB (-56.4%)
    firestore-lite (Write data)183 kB65.3 kB-118 kB (-64.4%)
  • firebase

    TypeBase (a6dc377)Merge (68a809a)Diff
    firebase-auth-compat.js125 kB125 kB+82 B (+0.1%)
    firebase-auth-react-native.js498 kB498 kB+431 B (+0.1%)
    firebase-auth.js418 kB418 kB+431 B (+0.1%)
    firebase-compat.js794 kB794 kB+82 B (+0.0%)
    firebase-firestore-lite.js845 kB267 kB-578 kB (-68.4%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/NMXrZUYBJY.html

@hsubox76 hsubox76 requested a review from egilmorez as a code owner July 7, 2022 19:08
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 7, 2022

Size Analysis Report 1

Affected Products

  • @firebase/auth

    • RecaptchaVerifier

      Size

      TypeBase (a6dc377)Merge (68a809a)Diff
      size37.8 kB37.9 kB+94 B (+0.2%)
      size-with-ext-deps57.5 kB57.6 kB+94 B (+0.2%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/Dr2k57JymB.html

@hsubox76 hsubox76 merged commit 1261d83 into master Jul 7, 2022
@hsubox76 hsubox76 deleted the ch-recaptcha-fix branch July 7, 2022 19:50
This was referenced Jul 7, 2022
@@ -112,7 +117,7 @@ export class ReCaptchaLoaderImpl implements ReCaptchaLoader {
// In cases (2) and (3), we _can't_ reload as it would break the recaptchas
// that are already in the page
return (
!!_window().grecaptcha &&
!!_window().grecaptcha?.render &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the late comment - !!_window().grecaptcha?.render can be replaced with librarySeparatelyLoaded, so this becomes:

return (this.librarySeparatelyLoaded && (hl === this.hostLanguage || this.counter > 0 || this.librarySeparatelyLoaded)

Can we just rewrite this as:

return (hl === this.hostLanguage || this.counter > 0 || this.librarySeparatelyLoaded)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See PR description, these 2 expressions were previously redundant as well before this code change, so I thought about fixing it but I didn't know the original intent, and if one of them was originally intended to be a different condition that also needed to be checked. I wanted to leave it up to someone more familiar with the code.

@firebase firebase locked and limited conversation to collaborators Aug 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RecaptchaVerifier error when used together with AppCheck
4 participants