Skip to content

Commit d8fdebb

Browse files
nikosdouvlisanagstef
authored andcommitted
feat(types,clerk-js): Bypass captcha for providers dynamically provided in environment (#4322)
1 parent a621127 commit d8fdebb

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

.changeset/shy-peaches-grow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@clerk/clerk-js": patch
3+
"@clerk/types": patch
4+
---
5+
6+
Bypass captcha for providers dynamically provided in environment

packages/clerk-js/src/core/resources/DisplayConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
DisplayConfigJSON,
66
DisplayConfigResource,
77
DisplayThemeJSON,
8+
OAuthStrategy,
89
PreferredSignInStrategy,
910
} from '@clerk/types';
1011

@@ -25,6 +26,7 @@ export class DisplayConfig extends BaseResource implements DisplayConfigResource
2526
captchaWidgetType: CaptchaWidgetType = null;
2627
captchaProvider: CaptchaProvider = 'turnstile';
2728
captchaPublicKeyInvisible: string | null = null;
29+
captchaOauthBypass: OAuthStrategy[] = [];
2830
homeUrl!: string;
2931
instanceEnvironmentType!: string;
3032
faviconImageUrl!: string;
@@ -84,6 +86,9 @@ export class DisplayConfig extends BaseResource implements DisplayConfigResource
8486
this.captchaWidgetType = data.captcha_widget_type;
8587
this.captchaProvider = data.captcha_provider;
8688
this.captchaPublicKeyInvisible = data.captcha_public_key_invisible;
89+
// These are the OAuth strategies we used to bypass the captcha for by default
90+
// before the introduction of the captcha_oauth_bypass field
91+
this.captchaOauthBypass = data.captcha_oauth_bypass || ['oauth_google', 'oauth_microsoft', 'oauth_apple'];
8792
this.supportEmail = data.support_email || '';
8893
this.clerkJSVersion = data.clerk_js_version;
8994
this.organizationProfileUrl = data.organization_profile_url;

packages/clerk-js/src/core/resources/SignUp.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,18 +339,19 @@ export class SignUp extends BaseResource implements SignUpResource {
339339
* We delegate bot detection to the following providers, instead of relying on turnstile exclusively
340340
*/
341341
protected shouldBypassCaptchaForAttempt(params: SignUpCreateParams) {
342-
if (
343-
params.strategy === 'oauth_google' ||
344-
params.strategy === 'oauth_microsoft' ||
345-
params.strategy === 'oauth_apple'
346-
) {
342+
if (!params.strategy) {
343+
return false;
344+
}
345+
346+
const captchaOauthBypass = SignUp.clerk.__unstable__environment!.displayConfig.captchaOauthBypass;
347+
348+
if (captchaOauthBypass.some(strategy => strategy === params.strategy)) {
347349
return true;
348350
}
351+
349352
if (
350353
params.transfer &&
351-
(SignUp.clerk.client?.signIn.firstFactorVerification.strategy === 'oauth_google' ||
352-
SignUp.clerk.client?.signIn.firstFactorVerification.strategy === 'oauth_microsoft' ||
353-
SignUp.clerk.client?.signIn.firstFactorVerification.strategy === 'oauth_apple')
354+
captchaOauthBypass.some(strategy => strategy === SignUp.clerk.client!.signIn.firstFactorVerification.strategy)
354355
) {
355356
return true;
356357
}

packages/types/src/displayConfig.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { DisplayThemeJSON } from './json';
22
import type { ClerkResource } from './resource';
3+
import type { OAuthStrategy } from './strategies';
34

45
export type PreferredSignInStrategy = 'password' | 'otp';
56
export type CaptchaWidgetType = 'smart' | 'invisible' | null;
@@ -19,6 +20,7 @@ export interface DisplayConfigJSON {
1920
captcha_widget_type: CaptchaWidgetType;
2021
captcha_public_key_invisible: string | null;
2122
captcha_provider: CaptchaProvider;
23+
captcha_oauth_bypass: OAuthStrategy[] | null;
2224
home_url: string;
2325
instance_environment_type: string;
2426
/* @deprecated */
@@ -55,6 +57,12 @@ export interface DisplayConfigResource extends ClerkResource {
5557
captchaWidgetType: CaptchaWidgetType;
5658
captchaProvider: CaptchaProvider;
5759
captchaPublicKeyInvisible: string | null;
60+
/**
61+
* An array of OAuth strategies for which we will bypass the captcha.
62+
* We trust that the provider will verify that the user is not a bot on their end.
63+
* This can also be used to bypass the captcha for a specific OAuth provider on a per-instance basis.
64+
*/
65+
captchaOauthBypass: OAuthStrategy[];
5866
homeUrl: string;
5967
instanceEnvironmentType: string;
6068
logoImageUrl: string;

0 commit comments

Comments
 (0)