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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-readers-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/auth': patch
---

Fix a bug causing ReCAPTCHA conflicts between Auth and App Check.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ export interface ReCaptchaLoader {
export class ReCaptchaLoaderImpl implements ReCaptchaLoader {
private hostLanguage = '';
private counter = 0;
private readonly librarySeparatelyLoaded = !!_window().grecaptcha;
/**
* Check for `render()` method. `window.grecaptcha` will exist if the Enterprise
* version of the ReCAPTCHA script was loaded by someone else (e.g. App Check) but
* `window.grecaptcha.render()` will not. Another load will add it.
*/
private readonly librarySeparatelyLoaded = !!_window().grecaptcha?.render;

load(auth: AuthInternal, hl = ''): Promise<Recaptcha> {
_assert(isHostLanguageValid(hl), auth, AuthErrorCode.ARGUMENT_ERROR);
Expand Down Expand Up @@ -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.

(hl === this.hostLanguage ||
this.counter > 0 ||
this.librarySeparatelyLoaded)
Expand Down