Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong language for actions/craft-recaptcha-3/default #22

Closed
desaulniers13 opened this issue Aug 9, 2021 · 8 comments
Closed

wrong language for actions/craft-recaptcha-3/default #22

desaulniers13 opened this issue Aug 9, 2021 · 8 comments

Comments

@desaulniers13
Copy link

desaulniers13 commented Aug 9, 2021

I get a 404 error because the script is looking at the wrong site (language). The plugin is using

scoreRequest.open("POST", "/{{ craft.app.config.general.actionTrigger }}/craft-recaptcha-3/default", true);

which brings to https://xxxx.com/en/actions/craft-recaptcha-3/default/ instead of https://xxxx.com/fr/actions/craft-recaptcha-3/default/

EN is still installed but disabled as we are only using FR at the moment. FR is already checked as the primary site in the settings... If I manually replace the line with the full FR url, the plugin works fine.

Thank you!

@clarknelson
Copy link
Owner

Thank you for reporting this. I've changed the line to use the current site's URL instead of a relative path.

scoreRequest.open("POST", "{{currentSite.baseUrl}}{{ craft.app.config.general.actionTrigger }}/craft-recaptcha-3/default", true);

Can you please pull down v1.1.4 and see if it works for you?

@desaulniers13
Copy link
Author

Thanks I see it's going for /fr/ now but I get another error, not sure if it's related, the repcatcha seems to always fail (my secret keep is saved in the settings):
XHRGEThttps://eeb2.288dev.com/fr/actions/craft-recaptcha-3/default/
[HTTP/2 200 OK 61ms]
error "There was no response key attached to the request, as provided by the front-end script. We can not continue without this key."

the code i'm using is:
{# Recaptcha #} {% include ['_recaptcha/frontend'] with {'action': 'contact'} %} <script> window.recaptcha_failure = function(response){ console.log('recaptcha failure'); console.log(response); } </script>

@clarknelson
Copy link
Owner

clarknelson commented Aug 10, 2021

I did change one other line (templates/frontend.twig:32):

csrfRequest.open("GET", "{{currentSite.baseUrl}}index.php?p={{ craft.app.config.general.cpTrigger }}/{{ craft.app.config.general.actionTrigger }}/users/session-info&dontExtendSession=1", true);

from:

csrfRequest.open("GET", "/index.php?p={{ craft.app.config.general.cpTrigger }}/{{ craft.app.config.general.actionTrigger }}/users/session-info&dontExtendSession=1", true);

thinking there may be a similar issue with the absolute URL. If you are able to test local changes can you see if it works with the absolute URL for the index.php script? I can change it back if that is the problem but it seems to work correctly for me. Is that a JS console error you posted?

@desaulniers13
Copy link
Author

desaulniers13 commented Aug 11, 2021

I tried with both lines (the before/after) and also with the complete direct URL https://xxxx.com/fr/actions/users/session-info&dontExtendSession=1 and it's the same result.

Yes its a console error
window.recaptcha_failure = function(response){ console.log('recaptcha failure'); console.log(response); }
, but also the response of GET https://xxxx.com/fr/actions/craft-recaptcha-3/default/ . Although I see in the console that it is calling POST https://www.google.com/recaptcha/api2/reload?k=my-key and it is the correct site key... :-\

@clarknelson
Copy link
Owner

Are you sure the front-end script is loading correctly? There is a test for the CSRF token which I believe may be failing.

scoreRequest.send('response=' + token + '&{{ craft.app.config.general.csrfTokenName }}=' + csrf);

The token is requested from the /index.php script, which you say is not working?
Can you make sure the config.general value is not the problem either?

array_key_exists('response', $request)

This conditional is failing which is why you are seeing There was no response key attached to the request...

@desaulniers13
Copy link
Author

Actually I managed to get a recaptcha success by replacing
scoreRequest.open("POST", "{{currentSite.baseUrl}}{{ craft.app.config.general.actionTrigger }}/craft-recaptcha-3/default", true);
with
scoreRequest.open("POST", "{{currentSite.baseUrl}}index.php?p={{ craft.app.config.general.cpTrigger }}/{{ craft.app.config.general.actionTrigger }}/craft-recaptcha-3/default", true);

using the same structure as you used above. If you think it makes sense, could you include it in the next version?

@clarknelson
Copy link
Owner

Okay I think it should be working for you in v1.1.5

Check to make sure the HTTP / HTTPS version is correct also, I saw a similar 400 error when visiting the wrong version.

@desaulniers13
Copy link
Author

great! thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants