Skip to content

Conversation

@GautheyValentin
Copy link

@GautheyValentin GautheyValentin commented Sep 1, 2022

With a env variable : GRAPHQL_JWT_REQUIRE_CAPTCHA set to true

Check if gRecaptchaResponse is existing and apply to $_POST['g-recaptcha-response']

@GautheyValentin GautheyValentin changed the title Add captcha support and execute filter wp_authenticate_user Add captcha support Sep 2, 2022
Copy link
Collaborator

@kidunot89 kidunot89 left a comment

Choose a reason for hiding this comment

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

@GautheyValentin While I think this functionality is necessary, I think there are some flaws in your approach. Please see my comments.

'mutateAndGetPayload' => function( $input, AppContext $context, ResolveInfo $info ) {
// Login the user in and get an authToken and user in response.
return Auth::login_and_get_token( sanitize_user( $input['username'] ), trim( $input['password'] ) );
return Auth::login_and_get_token( sanitize_user( $input['username'] ), trim( $input['password'] ), $input['gRecaptchaResponse'] );
Copy link
Collaborator

Choose a reason for hiding this comment

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

@GautheyValentin There needs to be validation of some kind for $input['gRecaptchaResponse'] seeing as it's not a required field it could be null.

* @since 0.0.1
*/
public static function login_and_get_token( $username, $password ) {
public static function login_and_get_token( $username, $password, $gRecaptchaResponse ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

$gRecaptchaResponse needs a default value otherwise it will throw an exception everytime it's value is null.
An @param entry in the docblock upon would be nice too. 👌🏿

throw new UserError( __( 'Captcha is required', 'wp-graphql-jwt-authentication' ) );
}

$_POST['g-recaptcha-response'] = $gRecaptchaResponse;
Copy link
Collaborator

@kidunot89 kidunot89 Jan 27, 2023

Choose a reason for hiding this comment

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

@GautheyValentin While I don't think this is bad practice and has it's uses in areas like testing, this is far from how the $_POST global was designed to be used. What you're trying to do here would probably be better addressed further up the funnel so to speak 🤔. Maybe see about getting an official filter in place within the reCaptcha plugin.

@GautheyValentin
Copy link
Author

@kidunot89 In wp-defender (Wpmudev extension) there is no filter to override de value of captcha response
If i remember correctly, other extensions have the same issue. Maybe we need to implement captcha directly in this plugin.

Code of wp-defender :

/**  * Get the reCAPTCHA API response.  *  * @param string $form  *  * @return bool  */ protected function recaptcha_response( string $form ): bool { if ( empty( $this->private_key ) || empty( $_POST['g-recaptcha-response'] ) ) { return false;	} // reCAPTCHA response post data. $response = stripslashes( sanitize_text_field( $_POST['g-recaptcha-response'] ) ); $remote_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP ); // @since v2.5.6 $remote_ip = (string) apply_filters( 'wd_recaptcha_remote_ip', $remote_ip ); $post_body = [ 'secret' => $this->private_key, 'response' => $response, 'remoteip' => $remote_ip,	]; $result = $this->service->recaptcha_post_request( $post_body ); // @since 2.5.6 return apply_filters( 'wd_recaptcha_check_result', $result, $form ); }

Best regards

@kidunot89
Copy link
Collaborator

I understand completely, I suggest the issue be opened to get a filter put in the official recaptcha plugin 🤔

@LZL0
Copy link

LZL0 commented Mar 24, 2023

Guys, I believe that this plugin should definitely include captcha support.
Let me know how I can assist.

@GautheyValentin GautheyValentin closed this by deleting the head repository Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants