Skip to content

Commit 25d37b0

Browse files
authored
fix(clerk-js): Revert removal of transfer strategy passing (#7962)
1 parent 03b4509 commit 25d37b0

9 files changed

Lines changed: 43 additions & 567 deletions

File tree

‎.changeset/strict-needles-taste.md‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎.changeset/twelve-foxes-obey.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/shared': minor
4+
---
5+
6+
Revert sign up if missing changes to fix Enterprise SSO captcha

‎packages/clerk-js/src/core/resources/SignIn.ts‎

Lines changed: 5 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
AuthenticateWithPopupParams,
1717
AuthenticateWithRedirectParams,
1818
AuthenticateWithWeb3Params,
19-
CaptchaWidgetType,
2019
ClientTrustState,
2120
CreateEmailLinkFlowReturn,
2221
EmailCodeConfig,
@@ -83,7 +82,6 @@ import {
8382
_futureAuthenticateWithPopup,
8483
wrapWithPopupRoutes,
8584
} from '../../utils/authenticateWithPopup';
86-
import { CaptchaChallenge } from '../../utils/captcha/CaptchaChallenge';
8785
import { runAsyncResourceTask } from '../../utils/runAsyncResourceTask';
8886
import { loadZxcvbn } from '../../utils/zxcvbn';
8987
import {
@@ -166,34 +164,12 @@ export class SignIn extends BaseResource implements SignInResource {
166164
this.fromJSON(data);
167165
}
168166

169-
create = async (params: SignInCreateParams): Promise<SignInResource> => {
167+
create = (params: SignInCreateParams): Promise<SignInResource> => {
170168
debugLogger.debug('SignIn.create', { id: this.id, strategy: 'strategy' in params ? params.strategy : undefined });
171-
172-
let body: Record<string, unknown> = { ...params };
173-
174-
// Inject browser locale
175-
const browserLocale = getBrowserLocale();
176-
if (browserLocale) {
177-
body.locale = browserLocale;
178-
}
179-
180-
if (
181-
this.shouldRequireCaptcha(params) &&
182-
!__BUILD_DISABLE_RHC__ &&
183-
!this.clientBypass() &&
184-
!this.shouldBypassCaptchaForAttempt(params)
185-
) {
186-
const captchaChallenge = new CaptchaChallenge(SignIn.clerk);
187-
const captchaParams = await captchaChallenge.managedOrInvisible({ action: 'signin' });
188-
if (!captchaParams) {
189-
throw new ClerkRuntimeError('', { code: 'captcha_unavailable' });
190-
}
191-
body = { ...body, ...captchaParams };
192-
}
193-
169+
const locale = getBrowserLocale();
194170
return this._basePost({
195171
path: this.pathRoot,
196-
body: body,
172+
body: locale ? { locale, ...params } : params,
197173
});
198174
};
199175

@@ -600,43 +576,6 @@ export class SignIn extends BaseResource implements SignInResource {
600576
return this;
601577
}
602578

603-
private clientBypass() {
604-
return SignIn.clerk.client?.captchaBypass;
605-
}
606-
607-
/**
608-
* Determines whether captcha is required for sign in based on the provided params.
609-
* Add new conditions here as captcha requirements evolve.
610-
*/
611-
private shouldRequireCaptcha(params: SignInCreateParams): boolean {
612-
if ('signUpIfMissing' in params && params.signUpIfMissing) {
613-
return true;
614-
}
615-
616-
return false;
617-
}
618-
619-
/**
620-
* We delegate bot detection to the following providers, instead of relying on turnstile exclusively
621-
*/
622-
protected shouldBypassCaptchaForAttempt(params: SignInCreateParams) {
623-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
624-
const captchaOauthBypass = SignIn.clerk.__internal_environment!.displayConfig.captchaOauthBypass;
625-
626-
// Check transfer strategy against bypass list
627-
if (params.transfer && SignIn.clerk.client?.signUp?.verifications?.externalAccount?.status === 'transferable') {
628-
const signUpStrategy = SignIn.clerk.client.signUp.verifications.externalAccount.strategy;
629-
return signUpStrategy ? captchaOauthBypass.some(strategy => strategy === signUpStrategy) : false;
630-
}
631-
632-
// Check direct strategy against bypass list
633-
if ('strategy' in params && params.strategy) {
634-
return captchaOauthBypass.some(strategy => strategy === params.strategy);
635-
}
636-
637-
return false;
638-
}
639-
640579
public __internal_updateFromJSON(data: SignInJSON | SignInJSONSnapshot | null): this {
641580
return this.fromJSON(data);
642581
}
@@ -875,80 +814,11 @@ class SignInFuture implements SignInFutureResource {
875814
});
876815
}
877816

878-
/**
879-
* Determines whether captcha is required for sign in based on the provided params.
880-
* Add new conditions here as captcha requirements evolve.
881-
*/
882-
private shouldRequireCaptcha(params: { signUpIfMissing?: boolean }): boolean {
883-
if (params.signUpIfMissing) {
884-
return true;
885-
}
886-
887-
return false;
888-
}
889-
890-
private shouldBypassCaptchaForAttempt(params: { strategy?: string; transfer?: boolean }) {
891-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
892-
const captchaOauthBypass = SignIn.clerk.__internal_environment!.displayConfig.captchaOauthBypass;
893-
894-
// Check transfer strategy against bypass list
895-
if (params.transfer && SignIn.clerk.client?.signUp?.verifications?.externalAccount?.status === 'transferable') {
896-
const signUpStrategy = SignIn.clerk.client.signUp.verifications.externalAccount.strategy;
897-
return signUpStrategy ? captchaOauthBypass.some(strategy => strategy === signUpStrategy) : false;
898-
}
899-
900-
// Check direct strategy against bypass list
901-
if (params.strategy) {
902-
return captchaOauthBypass.some(strategy => strategy === params.strategy);
903-
}
904-
905-
return false;
906-
}
907-
908-
private async getCaptchaToken(
909-
params: { strategy?: string; transfer?: boolean; signUpIfMissing?: boolean } = {},
910-
): Promise<{
911-
captchaToken?: string;
912-
captchaWidgetType?: CaptchaWidgetType;
913-
captchaError?: unknown;
914-
}> {
915-
if (
916-
!this.shouldRequireCaptcha(params) ||
917-
__BUILD_DISABLE_RHC__ ||
918-
SignIn.clerk.client?.captchaBypass ||
919-
this.shouldBypassCaptchaForAttempt(params)
920-
) {
921-
return {
922-
captchaToken: undefined,
923-
captchaWidgetType: undefined,
924-
captchaError: undefined,
925-
};
926-
}
927-
928-
const captchaChallenge = new CaptchaChallenge(SignIn.clerk);
929-
const response = await captchaChallenge.managedOrInvisible({ action: 'signin' });
930-
if (!response) {
931-
throw new Error('Captcha challenge failed');
932-
}
933-
934-
const { captchaError, captchaToken, captchaWidgetType } = response;
935-
return { captchaToken, captchaWidgetType, captchaError };
936-
}
937-
938817
private async _create(params: SignInFutureCreateParams): Promise<void> {
939-
const { captchaToken, captchaWidgetType, captchaError } = await this.getCaptchaToken(params);
940-
941-
const body: Record<string, unknown> = {
942-
...params,
943-
captchaToken,
944-
captchaWidgetType,
945-
captchaError,
946-
locale: getBrowserLocale() || undefined,
947-
};
948-
818+
const locale = getBrowserLocale();
949819
await this.#resource.__internal_basePost({
950820
path: this.#resource.pathRoot,
951-
body,
821+
body: locale ? { locale, ...params } : params,
952822
});
953823
}
954824

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ export class SignUp extends BaseResource implements SignUpResource {
173173
finalParams = { ...finalParams, ...captchaParams };
174174
}
175175

176+
if (finalParams.transfer && this.shouldBypassCaptchaForAttempt(finalParams)) {
177+
const strategy = SignUp.clerk.client?.signIn.firstFactorVerification.strategy;
178+
if (strategy) {
179+
finalParams = { ...finalParams, strategy: strategy as SignUpCreateParams['strategy'] };
180+
}
181+
}
182+
176183
return this._basePost({
177184
path: this.pathRoot,
178185
body: normalizeUnsafeMetadata(finalParams),
@@ -554,24 +561,22 @@ export class SignUp extends BaseResource implements SignUpResource {
554561
* We delegate bot detection to the following providers, instead of relying on turnstile exclusively
555562
*/
556563
protected shouldBypassCaptchaForAttempt(params: SignUpCreateParams) {
564+
if (!params.strategy) {
565+
return false;
566+
}
567+
557568
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
558569
const captchaOauthBypass = SignUp.clerk.__internal_environment!.displayConfig.captchaOauthBypass;
559570

560-
// For transfers, inspect the SignIn strategy to determine bypass logic
561-
if (params.transfer && SignUp.clerk.client?.signIn?.firstFactorVerification?.status === 'transferable') {
562-
const signInStrategy = SignUp.clerk.client.signIn.firstFactorVerification.strategy;
563-
564-
// OAuth transfer: Check if strategy is in bypass list
565-
if (signInStrategy?.startsWith('oauth_')) {
566-
return captchaOauthBypass.some(strategy => strategy === signInStrategy);
567-
}
568-
569-
// Non-OAuth transfer (signUpIfMissing): Captcha already validated during SignIn
571+
if (captchaOauthBypass.some(strategy => strategy === params.strategy)) {
570572
return true;
571573
}
572574

573-
// For direct SignUp (not transfer), check OAuth bypass
574-
if (params.strategy && captchaOauthBypass.some(strategy => strategy === params.strategy)) {
575+
if (
576+
params.transfer &&
577+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
578+
captchaOauthBypass.some(strategy => strategy === SignUp.clerk.client!.signIn.firstFactorVerification.strategy)
579+
) {
575580
return true;
576581
}
577582

@@ -782,24 +787,22 @@ class SignUpFuture implements SignUpFutureResource {
782787
}
783788

784789
private shouldBypassCaptchaForAttempt(params: { strategy?: string; transfer?: boolean }) {
790+
if (!params.strategy) {
791+
return false;
792+
}
793+
785794
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
786795
const captchaOauthBypass = SignUp.clerk.__internal_environment!.displayConfig.captchaOauthBypass;
787796

788-
// For transfers, inspect the SignIn strategy to determine bypass logic
789-
if (params.transfer && SignUp.clerk.client?.signIn?.firstFactorVerification?.status === 'transferable') {
790-
const signInStrategy = SignUp.clerk.client.signIn.firstFactorVerification.strategy;
791-
792-
// OAuth transfer: Check if strategy is in bypass list
793-
if (signInStrategy?.startsWith('oauth_')) {
794-
return captchaOauthBypass.some(strategy => strategy === signInStrategy);
795-
}
796-
797-
// Non-OAuth transfer (signUpIfMissing): Captcha already validated during SignIn
797+
if (captchaOauthBypass.some(strategy => strategy === params.strategy)) {
798798
return true;
799799
}
800800

801-
// For direct SignUp (not transfer), check OAuth bypass
802-
if (params.strategy && captchaOauthBypass.some(strategy => strategy === params.strategy)) {
801+
if (
802+
params.transfer &&
803+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
804+
captchaOauthBypass.some(strategy => strategy === SignUp.clerk.client!.signIn.firstFactorVerification.strategy)
805+
) {
803806
return true;
804807
}
805808

0 commit comments

Comments
 (0)