Skip to content

Commit

Permalink
fix(clerk-js): Add the render query param on the captcha script (#4332)
Browse files Browse the repository at this point in the history
Co-authored-by: panteliselef <[email protected]>
  • Loading branch information
anagstef and panteliselef authored Oct 15, 2024
1 parent 3b67cab commit 48421fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-moose-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/clerk-js": patch
---

Add the `?render=explicit` query parameter to the Turnstile script.
6 changes: 4 additions & 2 deletions packages/clerk-js/src/utils/captcha/turnstile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import type { CaptchaWidgetType } from '@clerk/types';

import { CAPTCHA_ELEMENT_ID, CAPTCHA_INVISIBLE_CLASSNAME } from './constants';

const CLOUDFLARE_TURNSTILE_ORIGINAL_URL = 'https://challenges.cloudflare.com/turnstile/v0/api.js';
// We use the explicit render mode to be able to control when the widget is rendered.
// CF docs: https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/#disable-implicit-rendering
const CLOUDFLARE_TURNSTILE_ORIGINAL_URL = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';

interface RenderOptions {
/**
Expand Down Expand Up @@ -87,7 +89,7 @@ async function loadCaptchaFromCloudflareURL() {
return await loadScript(CLOUDFLARE_TURNSTILE_ORIGINAL_URL, { defer: true });
} catch (err) {
console.warn(
'Clerk: Failed to load the CAPTCHA script from Clouflare. If you see a CSP error in your browser, please add the necessary CSP rules to your app. Visit https://clerk.com/docs/security/clerk-csp for more information.',
'Clerk: Failed to load the CAPTCHA script from Cloudflare. If you see a CSP error in your browser, please add the necessary CSP rules to your app. Visit https://clerk.com/docs/security/clerk-csp for more information.',
);
throw err;
}
Expand Down

0 comments on commit 48421fe

Please sign in to comment.