diff --git a/src/Netflex/Site/Support/CaptchaV2.php b/src/Netflex/Site/Support/CaptchaV2.php index a37d396..30bc503 100644 --- a/src/Netflex/Site/Support/CaptchaV2.php +++ b/src/Netflex/Site/Support/CaptchaV2.php @@ -62,12 +62,15 @@ public static function checkBox() */ public static function isValid() { - if (array_key_exists('g-recaptcha-response', $_GET)) - $response = $_GET['g-recaptcha-response']; - if (array_key_exists('g-recaptcha-response', $_POST)) - $response = $_POST['g-recaptcha-response'];; - if (!isset($response)) + $response = null; + + if (array_key_exists('g-recaptcha-response', $_REQUEST)) { + $response = $_REQUEST['g-recaptcha-response']; + } + + if (is_null($response)) { throw new ResponseMissingException('g-recaptcha-response is missing from $_GET and $_POST'); + } $response = json_decode(NF::$capi->post('https://www.google.com/recaptcha/api/siteverify', [ 'form_params' => [ diff --git a/tests/TestSuites/CaptchaV2/CaptchaV2.isValid.test.php b/tests/TestSuites/CaptchaV2/CaptchaV2.isValid.test.php index 952bbb5..b195e55 100644 --- a/tests/TestSuites/CaptchaV2/CaptchaV2.isValid.test.php +++ b/tests/TestSuites/CaptchaV2/CaptchaV2.isValid.test.php @@ -24,7 +24,7 @@ public function testThrowsExceptionWhenParametersMissing (): void { } public function testHandlesRequestException (): void { - $_GET['g-recaptcha-response'] = 'test'; + $_REQUEST['g-recaptcha-response'] = 'test'; NF::$capi->mockResponse(new Response(500)); NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff'); NF::$site->mockVariable('captcha_site_secret', '112233445566'); @@ -33,7 +33,7 @@ public function testHandlesRequestException (): void { } public function testHandlesValidCase (): void { - $_GET['g-recaptcha-response'] = 'test'; + $_REQUEST['g-recaptcha-response'] = 'test'; NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff'); NF::$site->mockVariable('captcha_site_secret', '112233445566'); NF::$capi->mockResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode([ @@ -48,7 +48,7 @@ public function testHandlesValidCase (): void { } public function testHandlesInvalidCase (): void { - $_GET['g-recaptcha-response'] = 'test'; + $_REQUEST['g-recaptcha-response'] = 'test'; NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff'); NF::$site->mockVariable('captcha_site_secret', '112233445566'); NF::$capi->mockResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode([