google recaptcha returns false due to "invalid-input-secret"

google recaptcha returns false due to "invalid-input-secret"

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Debugging invalid-input-secret in Google reCAPTCHA Verification

When a POST request hits your server and you immediately receive an invalid-input-secret error from Google, the diagnosis is almost always identical regardless of whether you are using Phalcon, Laravel, or raw PHP. The frontend view may appear flawless—the user sees the checkbox, clicks it, and the widget emits a token—but the backend validation fails before even considering that token valid.

In the scenario provided, the application uses the Phalcon framework to handle form validation. After checking standard fields like username, email, and password confirmation, the code attempts to verify the reCAPTCHA response via a cURL request. The critical issue lies in how the secret key is constructed within the $data array passed to curl_setopt.

The error log explicitly states: ["error-codes"] => ["invalid-input-secret"]. This specific error code means one thing: Google received your request, but the string you sent as the secret parameter does not match any registered secret key for your site ID.

The Secret Key Mismatch

Look closely at this section of the validation logic:

$data = array(
    'secret' => "my secret key",
    'response' => $post['g-recaptcha-response'],
    'remoteip' => $ip
);

The variable "my secret key" is clearly a placeholder or a hardcoded string used for demonstration, not the actual API key generated by Google. When you register a site in the Google reCAPTCHA Admin Console, you are provided with two keys: one for the Site Key (frontend) and one for the Secret Key (backend).

If you copy-paste the placeholder string into your production or even local environment, Google will reject it immediately because that string was never registered in their database. To fix this, you must replace "my secret key" with the exact 32-character hexadecimal string provided during site registration. This string is sensitive; you should never expose it in frontend code or commit it to public repositories without encryption or environment variable protection.

The CURLOPT_SSL_VERIFYPEER False Positive

There is a secondary, often overlooked configuration issue in the cURL setup:

curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);

In modern security practices, disabling peer verification (false) allows the connection to proceed even if the SSL certificate presented by the server is invalid or expired. While this might be necessary for self-signed internal APIs, it is generally considered a bad practice for external services like Google's endpoints.

Google uses strict SSL certificates. If your local environment (like XAMPP) has an issue with its CA bundle or date/time settings, disabling verification can sometimes mask underlying connectivity issues. However, in the specific case of invalid-input-secret, this setting is likely incidental. The error is strictly about authentication credentials, not transport security. That said, for a robust application, you should remove this line entirely and let cURL use the system's default certificate store. If local testing fails due to missing CA certificates, that is a separate environmental issue unrelated to the secret key itself.

Handling the Response Correctly

The code correctly initializes curl_init(), sets the URL to https://www.google.com/recaptcha/api/siteverify, and builds the POST payload using http_build_query(). The logic for decoding the JSON response is also sound:

$res = curl_exec($verify);
$captcha = json_decode($res);

if($captcha->success == false){
    // Handle error
}

However, a small improvement can be made to ensure you handle potential cURL errors gracefully. If the network request fails entirely (e.g., localhost DNS issues or internet connectivity), curl_exec might return an empty string or a specific error code rather than a JSON payload. Decoding an empty string results in null, which would cause a fatal error when accessing $captcha->success. You should check if $res is valid and decode it safely before checking the boolean flag.

Moving Forward

To resolve the immediate problem, locate your Site Verification Secret Key in the Google reCAPTCHA dashboard and replace the placeholder string in your Phalcon controller. Ensure that the key matches character-for-character, including any hyphens if present (though standard keys are usually continuous hex).

Once the correct secret is applied, the invalid-input-secret error will vanish, and you can proceed to inspect other potential failure modes, such as incorrect Site IDs or token expiration. If you find yourself managing multiple reCAPTCHA implementations across different frameworks, consider abstracting the verification logic into a dedicated service class to avoid repeating these configuration details in every controller.

Our network