Skip to content

fix(clerk-js): Stop retrying on /verify if the client cannot solve the challenge#5526

Merged
anagstef merged 11 commits intomainfrom
stefanos/fraud-566-stop-retrying-if-verify-is-failing
Apr 8, 2025
Merged

fix(clerk-js): Stop retrying on /verify if the client cannot solve the challenge#5526
anagstef merged 11 commits intomainfrom
stefanos/fraud-566-stop-retrying-if-verify-is-failing

Conversation

@anagstef
Copy link
Copy Markdown
Member

@anagstef anagstef commented Apr 3, 2025

Description

This PR:

  • Adds the captcha_action property on requests to the /verify endpoint in order to distinguish between heartbeat and requires_captcha
  • Stops the client from keep retrying to solve the captcha if they are not able to solve it (due to unsupported browser or other reasons)
  • Prevents the first /verify request on initialization if the client is captcha blocked, because components have not initialized yet.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@anagstef anagstef self-assigned this Apr 3, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 3, 2025

🦋 Changeset detected

Latest commit: f0e8ab5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2025 11:32am

@anagstef
Copy link
Copy Markdown
Member Author

anagstef commented Apr 3, 2025

!snapshot

@clerk-cookie
Copy link
Copy Markdown
Collaborator

Hey @anagstef - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.0.18-snapshot.v20250403182140
@clerk/astro 2.5.1-snapshot.v20250403182140
@clerk/backend 1.26.1-snapshot.v20250403182140
@clerk/chrome-extension 2.2.25-snapshot.v20250403182140
@clerk/clerk-js 5.59.1-snapshot.v20250403182140
@clerk/elements 0.23.10-snapshot.v20250403182140
@clerk/clerk-expo 2.9.8-snapshot.v20250403182140
@clerk/expo-passkeys 0.2.2-snapshot.v20250403182140
@clerk/express 1.4.1-snapshot.v20250403182140
@clerk/fastify 2.2.1-snapshot.v20250403182140
@clerk/localizations 3.13.6-snapshot.v20250403182140
@clerk/nextjs 6.13.1-snapshot.v20250403182140
@clerk/nuxt 1.5.1-snapshot.v20250403182140
@clerk/clerk-react 5.25.7-snapshot.v20250403182140
@clerk/react-router 1.2.1-snapshot.v20250403182140
@clerk/remix 4.5.13-snapshot.v20250403182140
@clerk/shared 3.3.1-snapshot.v20250403182140
@clerk/tanstack-react-start 0.13.1-snapshot.v20250403182140
@clerk/testing 1.4.35-snapshot.v20250403182140
@clerk/themes 2.2.28-snapshot.v20250403182140
@clerk/types 4.50.3-snapshot.v20250403182140
@clerk/vue 1.4.7-snapshot.v20250403182140

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/agent-toolkit@0.0.18-snapshot.v20250403182140 --save-exact

@clerk/astro

npm i @clerk/astro@2.5.1-snapshot.v20250403182140 --save-exact

@clerk/backend

npm i @clerk/backend@1.26.1-snapshot.v20250403182140 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@2.2.25-snapshot.v20250403182140 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.59.1-snapshot.v20250403182140 --save-exact

@clerk/elements

npm i @clerk/elements@0.23.10-snapshot.v20250403182140 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.9.8-snapshot.v20250403182140 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@0.2.2-snapshot.v20250403182140 --save-exact

@clerk/express

npm i @clerk/express@1.4.1-snapshot.v20250403182140 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.2.1-snapshot.v20250403182140 --save-exact

@clerk/localizations

npm i @clerk/localizations@3.13.6-snapshot.v20250403182140 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.13.1-snapshot.v20250403182140 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@1.5.1-snapshot.v20250403182140 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.25.7-snapshot.v20250403182140 --save-exact

@clerk/react-router

npm i @clerk/react-router@1.2.1-snapshot.v20250403182140 --save-exact

@clerk/remix

npm i @clerk/remix@4.5.13-snapshot.v20250403182140 --save-exact

@clerk/shared

npm i @clerk/shared@3.3.1-snapshot.v20250403182140 --save-exact

@clerk/tanstack-react-start

npm i @clerk/tanstack-react-start@0.13.1-snapshot.v20250403182140 --save-exact

@clerk/testing

npm i @clerk/testing@1.4.35-snapshot.v20250403182140 --save-exact

@clerk/themes

npm i @clerk/themes@2.2.28-snapshot.v20250403182140 --save-exact

@clerk/types

npm i @clerk/types@4.50.3-snapshot.v20250403182140 --save-exact

@clerk/vue

npm i @clerk/vue@1.4.7-snapshot.v20250403182140 --save-exact

@anagstef
Copy link
Copy Markdown
Member Author

anagstef commented Apr 7, 2025

!snapshot

@clerk-cookie
Copy link
Copy Markdown
Collaborator

Hey @anagstef - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.0.18-snapshot.v20250407083314
@clerk/astro 2.6.0-snapshot.v20250407083314
@clerk/backend 1.27.0-snapshot.v20250407083314
@clerk/chrome-extension 2.2.25-snapshot.v20250407083314
@clerk/clerk-js 5.59.1-snapshot.v20250407083314
@clerk/elements 0.23.10-snapshot.v20250407083314
@clerk/clerk-expo 2.9.8-snapshot.v20250407083314
@clerk/expo-passkeys 0.2.2-snapshot.v20250407083314
@clerk/express 1.4.1-snapshot.v20250407083314
@clerk/fastify 2.2.1-snapshot.v20250407083314
@clerk/localizations 3.13.6-snapshot.v20250407083314
@clerk/nextjs 6.14.0-snapshot.v20250407083314
@clerk/nuxt 1.5.1-snapshot.v20250407083314
@clerk/clerk-react 5.26.0-snapshot.v20250407083314
@clerk/react-router 1.2.1-snapshot.v20250407083314
@clerk/remix 4.5.13-snapshot.v20250407083314
@clerk/shared 3.4.0-snapshot.v20250407083314
@clerk/tanstack-react-start 0.13.1-snapshot.v20250407083314
@clerk/testing 1.4.35-snapshot.v20250407083314
@clerk/themes 2.2.28-snapshot.v20250407083314
@clerk/types 4.51.0-snapshot.v20250407083314
@clerk/vue 1.5.0-snapshot.v20250407083314

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/agent-toolkit@0.0.18-snapshot.v20250407083314 --save-exact

@clerk/astro

npm i @clerk/astro@2.6.0-snapshot.v20250407083314 --save-exact

@clerk/backend

npm i @clerk/backend@1.27.0-snapshot.v20250407083314 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@2.2.25-snapshot.v20250407083314 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.59.1-snapshot.v20250407083314 --save-exact

@clerk/elements

npm i @clerk/elements@0.23.10-snapshot.v20250407083314 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.9.8-snapshot.v20250407083314 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@0.2.2-snapshot.v20250407083314 --save-exact

@clerk/express

npm i @clerk/express@1.4.1-snapshot.v20250407083314 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.2.1-snapshot.v20250407083314 --save-exact

@clerk/localizations

npm i @clerk/localizations@3.13.6-snapshot.v20250407083314 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.14.0-snapshot.v20250407083314 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@1.5.1-snapshot.v20250407083314 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.26.0-snapshot.v20250407083314 --save-exact

@clerk/react-router

npm i @clerk/react-router@1.2.1-snapshot.v20250407083314 --save-exact

@clerk/remix

npm i @clerk/remix@4.5.13-snapshot.v20250407083314 --save-exact

@clerk/shared

npm i @clerk/shared@3.4.0-snapshot.v20250407083314 --save-exact

@clerk/tanstack-react-start

npm i @clerk/tanstack-react-start@0.13.1-snapshot.v20250407083314 --save-exact

@clerk/testing

npm i @clerk/testing@1.4.35-snapshot.v20250407083314 --save-exact

@clerk/themes

npm i @clerk/themes@2.2.28-snapshot.v20250407083314 --save-exact

@clerk/types

npm i @clerk/types@4.51.0-snapshot.v20250407083314 --save-exact

@clerk/vue

npm i @clerk/vue@1.5.0-snapshot.v20250407083314 --save-exact

anagstef added 2 commits April 7, 2025 14:03
…-if-verify-is-failing' into stefanos/fraud-566-stop-retrying-if-verify-is-failing
@anagstef anagstef requested a review from nikosdouvlis April 7, 2025 11:27
@anagstef anagstef marked this pull request as ready for review April 7, 2025 11:27
@anagstef anagstef requested review from octoper and panteliselef April 7, 2025 11:43
@anagstef anagstef changed the title fix(clerk-js): Stop retrying if /verify fails fix(clerk-js): Stop retrying on /verify if the client cannot solve the challenge Apr 7, 2025
Comment on lines +63 to +66
if (captchaParams?.captchaError !== 'modal_component_not_ready') {
await this.client.getOrCreateInstance().sendCaptchaToken(captchaParams);
this.captchaRetryCount = 0; // Reset the retry count on success
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If it's the first /client request on initialization it will always fail because we always initialize the components after the first /client request.

Comment thread packages/clerk-js/src/core/fraudProtection.ts Outdated
Comment thread packages/clerk-js/src/core/fraudProtection.ts Outdated
@anagstef
Copy link
Copy Markdown
Member Author

anagstef commented Apr 8, 2025

!snapshot

@clerk-cookie
Copy link
Copy Markdown
Collaborator

Hey @anagstef - the snapshot version command generated the following package versions:

Package Version
@clerk/chrome-extension 2.2.26-snapshot.v20250408113211
@clerk/clerk-js 5.59.2-snapshot.v20250408113211
@clerk/clerk-expo 2.9.9-snapshot.v20250408113211

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/chrome-extension

npm i @clerk/chrome-extension@2.2.26-snapshot.v20250408113211 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.59.2-snapshot.v20250408113211 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.9.9-snapshot.v20250408113211 --save-exact

Copy link
Copy Markdown
Member

@nikosdouvlis nikosdouvlis left a comment

Choose a reason for hiding this comment

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

as @anagstef raised, the logic here has become pretty complex and is due for a refactor. We'd also need to add some kind of UI for the C2 users explaining why the captcha failed

@anagstef anagstef merged commit eb67419 into main Apr 8, 2025
30 checks passed
@anagstef anagstef deleted the stefanos/fraud-566-stop-retrying-if-verify-is-failing branch April 8, 2025 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants