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

Extract Captcha logic and robot detection to an abstractions library #5932

Closed
wants to merge 6 commits into from

Conversation

chaaboah
Copy link

Hi there :)
I know this is related to an old issue (#2078) and it was solved by adding an Orchard Core ReCAPTCHA module (pull request #2192).
But i think that extracting the Robot detection and the Captcha behavior, will help the Community to build other Captcha modules with other providers (like hCaptcha who gained popularity thanks to cloudflare).
I'm working on a multi provider Captcha module but it's not ready yet :)
This pull request shouldn't introduce breaking changes, hope my work will help :)

P.S : even if my pull request is rejected i think the method "ProcessAsync" from the RecaptchaTagHelper should be optimized because it has currently an avoidable call to the ReCAPTCHA API

@dnfclas
Copy link

dnfclas commented Apr 13, 2020

CLA assistant check
All CLA requirements met.

@infofromca
Copy link
Contributor

Hi there :)
I know this is related to an old issue (#2078) and it was solved by adding an Orchard Core ReCAPTCHA module (pull request #2192).
But i think that extracting the Robot detection and the Captcha behavior, will help the Community to build other Captcha modules with other providers (like hCaptcha who gained popularity thanks to cloudflare).
I'm working on a multi provider Captcha module but it's not ready yet :)
This pull request shouldn't introduce breaking changes, hope my work will help :)
P.S : even if my pull request is rejected i think the method "ProcessAsync" from the RecaptchaTagHelper should be optimized because it has currently an avoidable call to the ReCAPTCHA API

hi great. this is what I need.
#2192 (comment)

@Skrypt
Copy link
Contributor

Skrypt commented Apr 17, 2020

I think the method "ProcessAsync" from the RecaptchaTagHelper should be optimized because it has currently an avoidable call to the ReCAPTCHA API

Elaborate?

@chaaboah
Copy link
Author

@Skrypt first of all an erratum: it's an avoidable call to the Robot detection API (IDetectRobot interface) and not ReCaptcha API.
So the first problem happens in line 55:
var robotDetected = robotDetectors.Invoke(d => d.DetectRobot(), _logger).Any(d => d.IsRobot) && Mode == ReCaptchaMode.PreventRobots;
Because the && is "short-circuiting" it's better to evaluate the mode before the invokation of robotDetectors, which gives us this ne line :
var robotDetected =Mode == ReCaptchaMode.PreventRobots && robotDetectors.Invoke(d => d.DetectRobot(), _logger).Any(d => d.IsRobot) ;
We can also add more optimizations to "ProcessAsync" by avoiding service resolution if the mode is 'AlwaysDisplay'.
Last point, the check "if the Recaptcha is configured" happens too late, it should be at the beginning so we avoid any further processing if it's FALSE.
All the points are implemented in the commit of this pull request :)
Hope this helped to clarify my PS :)

@agriffard agriffard requested a review from Skrypt October 5, 2020 13:11
Copy link
Contributor

@Skrypt Skrypt left a comment

Choose a reason for hiding this comment

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

I agree with the effort of abstracting these services. I will try to review the code to make sure everything is fine. But I think from a first quick glance it looked good.

@agriffard
Copy link
Member

Please fix the conflicts.

@chaaboah
Copy link
Author

Conflict fixed :)

@Piedone
Copy link
Member

Piedone commented Jan 11, 2024

I sincerely apologize for us taking so much time here. I checked out the PR, going over old ones, and this would be quite useful, though with some adjustments, and updated to the latest source.

Is this something you'd like to revisit any time soon @chaaboah or should we close?

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

@Piedone
Copy link
Member

Piedone commented Mar 13, 2024

Closing due to inactivity.

@Piedone Piedone closed this Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants