PluginProbe
Contact Forms by Cimatti / 1.9.2
Contact Forms by Cimatti v1.9.2
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
← All changes | classes/Validation/Captcha2b.php +27 -43 2.2.41.9.2 View file →
@@ -1,54 +1,38 @@
1 1 <?php
2 -/**
3 - * reCAPTCHA v2 Validation
4 - *
5 - * @package Contact Forms
6 - */
7 -
8 -// phpcs:disable WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput -- Server-side CAPTCHA validation requires POST data
9 -
10 2 class AccuaForm_Validation_Captcha2b extends Validation {
11 - protected $message = 'Error: The reCAPTCHA response provided was incorrect. Please retry.';
3 + protected $message = "Error: The reCATPCHA response provided was incorrect. Please re-try.";
12 4 protected $privateKey;
5 +
6 + public function isValid($value) {
7 + if (!isset($_POST['g-recaptcha-response'])) {
8 + return false;
9 + }
13 10
14 - public function isValid( $value ) {
15 - if ( ! isset( $_POST['g-recaptcha-response'] ) ) {
16 - return false;
17 - }
11 + $response = stripslashes_deep($_POST['g-recaptcha-response']);
18 12
19 - $response = stripslashes_deep( $_POST['g-recaptcha-response'] );
13 + if ($response === '') {
14 + return false;
15 + }
20 16
21 - if ( '' === $response ) {
22 - return false;
23 - }
17 + $url = 'https://www.google.com/recaptcha/api/siteverify'
18 + .'?secret='.urlencode($this->privateKey)
19 + .'&response='.urlencode($response)
20 + .'&remoteip='.urlencode($_SERVER["REMOTE_ADDR"]);
24 21
25 - $verify_url = 'https://www.google.com/recaptcha/api/siteverify';
22 + $ch = curl_init();
23 + curl_setopt($ch, CURLOPT_URL, $url);
24 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
25 + curl_setopt($ch, CURLOPT_TIMEOUT, 20);
26 + $res = curl_exec($ch);
27 + curl_close($ch);
26 28
27 - $verify_data = array(
28 - 'secret' => $this->privateKey,
29 - 'response' => $response,
30 - 'remoteip' => isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '',
31 - );
29 + if ($res !== false) {
30 + @ $res = json_decode($res, true);
31 + if (!empty($res['success'])) {
32 + return true;
33 + }
34 + }
32 35
33 - $response_obj = wp_remote_post(
34 - $verify_url,
35 - array(
36 - 'body' => $verify_data,
37 - 'timeout' => 20,
38 - )
39 - );
40 -
41 - if ( is_wp_error( $response_obj ) ) {
42 - return false;
43 - }
44 -
45 - $body = wp_remote_retrieve_body( $response_obj );
46 - $result = json_decode( $body, true );
47 -
48 - if ( ! empty( $result['success'] ) ) {
49 - return true;
50 - }
51 -
52 - return false;
36 + return false;
53 37 }
54 38 }