I got "timeout-or-duplicate" error using ReCaptcha v3

I got "timeout-or-duplicate" error using ReCaptcha v3

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

Stefan Bogdanescu

Founder & Senior Architect

I got "timeout-or-duplicate" error using ReCaptcha v3

When integrating reCAPTCHA v3 into a Laravel application, the timeout-or-duplicate error is one of the most common stumbling blocks. It indicates that Google has already processed the specific token you are sending in your current request. This isn't usually a logic error in your code; it is almost exclusively an architectural issue regarding how the verification request is triggered relative to the form submission.

The Root Cause: Double Verification

In your implementation, the JavaScript executes grecaptcha.execute() immediately when the script loads. This generates a token and places it into the hidden input field named recaptcha_response. At this stage, you have successfully communicated with Google and received a valid token for that specific user session.

However, the critical mistake lies in your controller logic. You are attempting to verify the token again using the same endpoint (grecaptcha/api/siteverify) inside your Laravel route. The reCAPTCHA API is stateful regarding verification requests. Once you successfully call siteverify with a token, that token becomes "consumed." If you attempt to verify it again—whether by refreshing the page and resending the form, or even if the network request takes longer than expected—the API returns timeout-or-duplicate.

Essentially, you are treating reCAPTCHA as an input field where the value changes every time you type something. It is not. The hidden input holds a single-use cryptographic token. Once used for verification, it is dead.

Correct Implementation Strategy

To fix this, you must decouple the execution of the challenge from the verification of the response.

  1. Execution: Run grecaptcha.execute() on page load or after a user interaction (like scrolling or clicking). Store the returned token in your hidden input field.
  2. Submission: When the form is submitted, send that stored token to your backend.
  3. Verification: Your Laravel controller receives the token and calls the Google API once. If successful, process the data. Do not attempt to verify the same token again.

Your current code actually performs step 3 correctly in principle (calling siteverify in the controller), but the error suggests the token is being consumed before it reaches your backend or that the network latency on the client side causes a race condition where the browser retries or the logic assumes a fresh token was generated upon refresh.

The most robust pattern for reCAPTCHA v3 is to verify the token only after the form submission AJAX call completes, ensuring the token hasn't been "used up" by an intermediate step.

Optimizing Your Laravel Controller

Your controller currently looks like this:

// Inside ContactController@send
$recaptcha_response = $_POST['recaptcha_response'];
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_secret = 'My_Secret_Key'; // Use environment variables in production!
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);

This approach is functional if the token is fresh, but it relies on file_get_contents, which can be unreliable depending on server configurations (e.g., allow_url_fopen settings). A more modern Laravel approach uses Guzzle or the built-in HTTP client.

Here is a refined version of your verification logic:

use Illuminate\Support\Facades\Http;

public function send(Request $request) {
    // ... validation for name, email, etc. ...

    $recaptchaResponse = $request->input('recaptcha_response');
    $recaptchaSecret = config('services.recaptcha.secret');

    try {
        $response = Http::post('https://www.google.com/recaptcha/api/siteverify', [
            'secret' => $recaptchaSecret,
            'response' => $recaptchaResponse
        ]);

        $data = $response->json();

        if ($data['success']) {
            // Score check happens here
            if ($data['score'] < 0.5) {
                return response()->json(['response' => 'Vous êtes considéré comme Bot/Spammer !', 'score' => $data['score']], 422);
            }

            // Proceed with sending mail
            Mail::send(/* ... */);
            
            return response()->json(['response' => 'success']);
        } else {
            // Handle specific error codes if needed, though success is usually false for timeout/duplicate
            return response()->json(['response' => 'recaptcha verification failed', 'error-codes' => $data['error-codes']], 422);
        }
    } catch (\Exception $e) {
        // Log the exception and handle gracefully
        return response()->json(['response' => 'Internal Server Error'], 500);
    }
}

Handling Frontend Conflicts

You are using SweetAlert (swal) with e.preventDefault(). This is excellent for UX. However, ensure that the hidden input containing the token is populated before the SweetAlert confirmation fires.

In your JavaScript, you have:

grecaptcha.ready(function () {
    grecaptcha.execute('My_Site_Key', { action: 'contact' }).then(function (token) {
        var recaptchaResponse = document.getElementById('recaptchaResponse');
        recaptchaResponse.value = token;
    });
});

This code runs immediately. If the user refreshes the page, this script re-runs, generating a new token. This is correct behavior. The problem arises if your backend logic or network issues cause the first verification to fail (e.g., timeout), and then the user retries. If they retry without clearing the old token from memory (which they can't, as it's in the input field), you might be double-verifying.

The timeout-or-duplicate error specifically means the backend called siteverify, got a result, and that specific token is now invalid. It does not mean the token is "wrong." It means it was used.

If you see this error persistently, check your server logs or network tab to ensure there isn't a duplicate AJAX request being sent due to race conditions in your SweetAlert logic. Ensure the form submission only happens once per user action.

Configuration Best Practices

Finally, never hardcode your My_Secret_Key in the code. In a production Laravel environment, use the .env file:

RECAPTCHA_SITE_KEY=6Ld9a... (public)
RECAPTCHA_SECRET_KEY=6Ld9a... (private)

And update your config files to read from these variables. This prevents accidental exposure of your private key and allows for easier debugging if you need to regenerate a token or change keys.

By ensuring the verification logic runs exactly once per form submission and that the token is generated fresh on every page load, you will eliminate the timeout-or-duplicate error. The key takeaway is respecting the stateless nature of reCAPTCHA tokens: generate, store, verify once

Our network