Flynntes / Sleeky

🎨 A sleek and simple frontend & backend theme for YOURLS
http://sleeky.flynntes.com
MIT License
463 stars 99 forks source link

reCAPTCHA v3 not working #71

Open RuudvanReenen opened 3 years ago

RuudvanReenen commented 3 years ago

Thanks for a great looking theme for YOURLS!

I have an issue with getting reCAPTCHA v3 working on the front end: When submitting the form, the $_POST data only contains the 'url' and 'keyword' values, there are no other keys/values in $_POST. So the necessary 'token' (or 'g-recaptcha-response'?) and 'action' are missing:

This is $_POST : array(2) { ["url"]=> string(34) "https://github.com/Flynntes/Sleeky" ["keyword"]=> string(0) "" }

So this makes the final reCAPTCHA verification respond with: { "success": false, "error-codes": [ "missing-input-response" ] } and the page shows: reCAPTCHA failed

Settings: enableRecaptcha is enabled and recaptchaV3SiteKey and recaptchaV3SecretKey are both set correctly in config.php. The recaptchaV3SiteKey also shows correctly in the resulting HTML for api.js?render= and as first parameter of grecaptcha.execute.

Any idea how to fix this? Thanks!

RuudvanReenen commented 3 years ago

This can be fixed by preventing the default form button execution:

Add the following line after line 6 in the frontend/footer.php: event.preventDefault();

Should look like this:

<script>
    $('#shortenlink').submit(function(event) {
        if (<?php echo (int)enableRecaptcha  ?>) {
            event.preventDefault();
                        grecaptcha.ready(function() { etc. etc.
ihatemyisp commented 3 years ago

@RuudvanReenen thanks for this. I spent more time than I care to admit trying to fix this.

Oddly, it works fine in Safari without the fix, only Firefox complains.

irrweg commented 3 years ago

Oddly, it works fine in Safari without the fix, only Firefox complains.

I have 2 different Firefox Installed, the normal one and the Developer Version. On the normal one the reCAPTCHA logo shows up on the bottom right corner, the Developer Version does not show the logo. I think some addons interfere on Firefox, don't know which one, need to make a new profile and install every addon one after another.

@RuudvanReenen Anyway the fix worked. Thanks!

yyppsk commented 3 years ago

Source https://blog.chromium.org/2021/05/update-on-user-agent-string-reduction.html

We plan to gradually reduce, in a phased manner, the granularity of available information in the User-Agent header field, as well as the navigator.userAgent, navigator.appVersion, and navigator.platform JS APIs.

Once this is complete, you will still be able to reliably get the browser major version, platform name, and distinguish between desktop and mobile (or tablet), solely from the User-Agent string. For more advanced use cases, you should migrate to the User Agent Client Hints API.

Note: We have no plans to change the User-Agent string on Android WebView or Chrome for iOS at this time, but will make public updates if and when that changes.

Our current high-level plan is as follows:

Beginning in M92, we plan to start sending deprecation notices for the navigator.userAgent, navigator.appVersion, and navigator.platform getters in the DevTools Issues tab. In the coming weeks, we will announce an Origin Trial for sites to opt in to receiving the fully reduced User-Agent. We expect to run the Origin Trial for at least 6 months to provide enough time for sites to opt in, test, and provide feedback on the feasibility and compatibility of our desired end state. We will evaluate feedback from Origin Trial partners and the community, and based on this feedback proceed to Phases 3 through 7 of our plan (see next section for details), giving the ecosystem adequate time to adapt in between them. Otherwise, depending on feedback we will reconsider the best course of action. For sites with complex use cases that require more time for migration, we aim to offer the ability to extend the current User-Agent behavior for at least an additional 6 months (through a "reverse Origin Trial"). Proposed rollout plan We plan to roll out these changes slowly and incrementally in 7 Phases—pending Origin Trial feedback—and plan to publish an update soon on the proposed timing and milestones beyond Phase 1.

Reduction Preparation Phase 1: Warn about accessing navigator.userAgent, navigator.appVersion, and navigator.platform in DevTools, beginning in M92.

This is mentioned on Chrome blogs, and in my dev console, it shows prevention to ReCaptcha js. Also, my frontend config looks different,

<?php if (enableRecaptcha) : ?>
    <script src="https://www.google.com/recaptcha/api.js?render=<?php echo recaptchaV3SiteKey ?>"></script>
    <script>
        const shortenForm = document.querySelector("form#shortenlink");
        if (shortenForm) {
            shortenForm.addEventListener("submit", function(e){
                e.preventDefault();
                grecaptcha.ready(function() { etc..

How can I fix my Recaptcha?

image

un99known99 commented 2 years ago

hiya, any updates on that topic, it is same for me, recaptcha not working, same: <?php if (enableRecaptcha) : ?>

<script>
    const shortenForm = document.querySelector("form#shortenlink");
    if (shortenForm) {
        shortenForm.addEventListener("submit", function(e){
         ==>    e.preventDefault();
            grecaptcha.ready(function() { etc..

for me here, seems quick fix applies not in this case.

Any findings?

gjelbrim commented 1 year ago

Hej,

I ran into the same issue, but I was able to resolve it by deactivating the standard reCaptcha plugin.