Closed (fixed)
Project:
Cloudflare Turnstile
Version:
1.1.16
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 Mar 2025 at 21:12 UTC
Updated:
18 Mar 2025 at 18:34 UTC
Jump to comment: Most recent
Comments
Comment #2
greatmatter commentedWhat error (if any) are you receiving?
Comment #3
glynster commentedI am debugging at the moment to try and be useful. There are no console errors. However here are some observations:
Locally it does load fine.
On production it does not.
Markup wise I can see
<div class="cf-turnstile" data-sitekey="################" data-theme="light" data-size="normal" data-language="auto" data-retry="auto" interval="8000" data-appearance="always"></div>but on version 1.1.13 the markup is:
<div class="cf-turnstile" data-sitekey="################" data-theme="light" data-size="normal" data-language="auto" data-retry="auto" interval="8000" data-appearance="always"><div><input type="hidden" name="cf-turnstile-response" id="cf-chl-widget-b5dkd_response" value="TOKEN"></div></div>Comment #4
greatmatter commentedI think I got it--I've just pushed a hotfix to 1.1.16
Comment #5
glynster commentedSo it seems this actually fixes the issue:
1. Run This in Browser Console to Force a Reset
document.querySelectorAll('.cf-turnstile').forEach(el => {
turnstile.remove(el);
});
turnstile.render('.cf-turnstile', { sitekey: "######" });
2. Modify the Form Rendering Code to Prevent Duplicate Initialization
To avoid this problem, modify your Drupal form rendering:
Then add this script in turnstile.ajax.js to remove any existing Turnstile instances before rendering a new one:
Comment #6
greatmatter commentedWould you mind letting me know if 1.1.16 fixes it for you?
Comment #7
glynster commented@greatmatter thanks so much for being so responsive. I just deployed with your new hotfix and sadly I get the same results, fails to load/initialize.
As soon as I run this in the console on production it loads:
turnstile.render('.cf-turnstile', { sitekey: "#################" });
Comment #8
greatmatter commentedHow odd--I've tested it across our sites--would you mind clearing your caches (including edge caches, if any)?
Comment #9
glynster commentedNo luck on my end We have cleared caches Drupal, Varnish, Cloudflare, etc. The only fix is this:
turnstile.render('.cf-turnstile', { sitekey: "#################" });
With the current version or revert to 1.1.13.
Comment #10
greatmatter commentedPlease try resaving your keys--I'm wondering if something weird happened with the upgrading/downgrading.
Comment #11
glynster commentedI wish I could have good news and it be that simple but it is not.
This seems to work:
Comment #12
glynster commentedComment #13
greatmatter commentedI cannot seem to replicate this issue. The code you sent will likely break the Form/AJAX functionality (using EventSubscriber) introduced in 1.1.10.
I'm wondering if, for some reason, the
Comment #14
glynster commentedOnly 1, nothing fancy going on here. These are just basic webforms and GIn Login pages.
Comment #15
glynster commentedOkay well all our sites are behind Cloudflare and as soon as we disable RocketLoader it works. But we have always used this service. Since the change this is now conflicting it seems.
Comment #16
keiserjb commentedI was getting cookie errors in the Chrome console.
Reading cookie in cross-site context may be impacted on Chrome
Cookies with the SameSite=None; Secure and not Partitioned attributes that operate in cross-site contexts are third-party cookies. Chrome is moving towards a new experience that allows users to choose to browse without third-party cookies.
Learn more from the linked article about preparing your site to avoid potential breakage.
It listed multiple cookies from the the cloudflare domain.
Thanks for the tip about Rocket Loader in Cloudflare. I turned that off and it started working.
Comment #17
keiserjb commentedRolling back to 1.1.13 works as well.
Comment #18
greatmatter commentedHm. I wonder why it's working in our sites. We're behind Cloudflare, but don't use RocketLoader. We also have SameSite=Lax - so I'm wondering if that plays a role. I'm open to ideas of how to make this work.
@keiserjb - what errors are you getting in the console?
The big change between versions was how the main Cloudflare Turnstile script was being included. We could add to the turnstile_library_info_build() the defer and async attributes--would you mind testing that to let me know if that changes anything? I'm not going to make a patch before knowing if it works for you.
EDIT: here's the change to 1.1.16:
Comment #19
glynster commented@greatmatter you are referring to the services file right?
We already have this set on our sites, so we can rule that one out.
I can confirm that updating the widget does resolve the issue
Comment #20
glynster commentedYes this suggestion resolves the issue and it much better that what I suggested:
Adding the defer and async allows everything to get along and Rocketloader can be reinstated. Win, win.
Comment #21
keiserjb commentedChanging hook_library_info_build works for me as well with 1.1.16.
I had trouble replicating this problem after discovery last week as it still worked locally and on my dev site. Today, I was able to find out how to break Turnstile on my dev site by adding a domain. Then I got the cross-site cookie errors just like production. The js alterations fix it though.
Comment #22
greatmatter commentedOk, it's all fixed in 1.1.17. Thanks, everyone!
Comment #23
glynster commentedRockstar thank you so much for pushing this fix.
Comment #24
greatmatter commented