Skip to main content

Hello, 

I’m having issues with https://www.google.com/recaptcha/api/siteverify. I’m calling this via cUrl from a php laravel app. I’m using php 8.3
Here is the cUrl function which I’m using

$captchaResults = Utility::curlCall(    'https://www.google.com/recaptcha/api/siteverify',    'POST',    $captchaParams);
public static function curlCall(    $url,    $type = 'GET',    $arguments = [],    $encodeData = false,    $returnHeaders = false) {    $type = strtoupper($type);    if ($type == 'GET') {        $url .= '?'.http_build_query($arguments);    }    $curl_request = curl_init($url);    if ($type == 'POST') {        curl_setopt($curl_request, CURLOPT_POST, 1);    } elseif ($type == 'PUT') {        curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, 'PUT');    } elseif ($type == 'DELETE') {        curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, 'DELETE');    }    curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);    curl_setopt($curl_request, CURLOPT_HEADER, $returnHeaders);    curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);    curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);    if (! empty($arguments) && $type !== 'GET') {        if ($encodeData) {            // encode the arguments as JSON            $arguments = json_encode($arguments);        }        curl_setopt($curl_request, CURLOPT_POSTFIELDS, $arguments);    }    $result = curl_exec($curl_request);    if ($returnHeaders) {        // set headers from response        [$headers, $content] = explode("\r\n\r\n", $result, 2);        foreach (explode("\r\n", $headers) as $header) {            header($header);        }        return trim($content);    }    $httpCode = curl_getinfo($curl_request, CURLINFO_HTTP_CODE);    curl_close($curl_request);    // decode the response from JSON    $response = json_decode($result);    return ['code' => $httpCode, 'response' => $response];}I’m getting the error “OpenSSL SSL_read: OpenSSL/3.5.0: error:0A000126:SSL routines::unexpected eof while reading, errno 0” There is no code change in cUrl or on how its called.  After searching for a while i got to know that upon commenting below line works.
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
But I want to understand what happened suddenly that it stopped working.

Two suggestions.

1) I would try to remove this line

curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);

HTTP 1.0 is very old and I would not rely on this support. By omitting this option curl will determine the HTTP version it feels is appropriate.

2) I would also change to

curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 1);

Otherwise you are disabling SSL cert verification which introduces vulnerabilities, and is also likely the cause of the OpenSSL error

 


@CoryKramer  Thanks for looking into it. We have already removed curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);.

 

My question is why it stopped suddenly? It was working pretty well earlier with the same code.


Reply