Google Recaptcha missing-input-secret
By Flavio
Published · Updated
Tagged: JavaScript
Fix reCAPTCHA's missing-input-secret error: send the siteverify request as form fields, not JSON. Plus what every error code means, how to check score, action and hostname, and the test keys.
Was trying to make Google Recaptcha work but kept getting failed attempts and the error missing-input-secret back.
After checking that my secret key was correct, I realized the verification endpoint does not expect a JSON body. It expects the values as form fields, URL-encoded.
I was sending the values in the body as JSON:
const response = await fetch('https://www.google.com/recaptcha/api/siteverify', {
method: "POST",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
secret: CAPTCHA_SITE_SECRET,
response: CAPTCHA_VALUE_FROM_CLIENT
})
})
Google ignores a JSON body completely, so from its point of view the request had no secret and no token.
Send the request from your server, with the values in a URLSearchParams body:
const response = await fetch(
'https://www.google.com/recaptcha/api/siteverify',
{
method: 'POST',
body: new URLSearchParams({
secret: CAPTCHA_SITE_SECRET,
response: CAPTCHA_VALUE_FROM_CLIENT
})
}
)
const result = await response.json()
if (!result.success) {
console.error(result['error-codes'])
}
When you pass a URLSearchParams object as the body, fetch() sets the application/x-www-form-urlencoded content type for you. Don’t set Content-Type: application/json on top of it.
When I tested this again in November 2026, the endpoint answered invalid-input-response both to a JSON body and to a request with no fields at all. So you might see that code instead of missing-input-secret. The cause and the fix are the same.
The request parameters
The endpoint is https://www.google.com/recaptcha/api/siteverify and it takes a POST request with these fields:
secret(required): your secret key, the one Google shows next to the site keyresponse(required): the token the reCAPTCHA widget gave you in the browserremoteip(optional): the user’s IP address
Mixing up the two keys is another common mistake. The site key goes in your HTML. The secret key stays on the server, in an environment variable. Never send it to the browser.
You can test the endpoint from the terminal with curl, which sends form fields with -d:
curl -X POST https://www.google.com/recaptcha/api/siteverify \
-d "secret=YOUR_SECRET_KEY" \
-d "response=TOKEN_FROM_THE_BROWSER"
What the error codes mean
| Error code | Meaning |
|---|---|
missing-input-secret | The secret parameter is missing |
invalid-input-secret | The secret parameter is invalid or malformed |
missing-input-response | The response parameter (the token) is missing |
invalid-input-response | The response parameter is invalid or malformed |
bad-request | The request is invalid or malformed |
timeout-or-duplicate | The token is too old, or it was already verified |
timeout-or-duplicate trips people up. Each token is valid for two minutes and can be verified only once. You get this error when:
- your code calls siteverify twice for the same token, for example once in a middleware and once in the route
- the user takes more than two minutes to submit the form after the token was created
- the user submits the form twice with the same token
With reCAPTCHA v3, ask for the token when the user submits the form, not when the page loads. Then it’s always fresh.
Check more than success
A successful v2 response looks like this:
{
"success": true,
"challenge_ts": "2026-11-25T06:02:23Z",
"hostname": "example.com"
}
hostname is the site where the user solved the challenge. Compare it with your own domain, so a token created on another site can’t be used on yours.
reCAPTCHA v3 doesn’t show a challenge. It gives each request a score instead, plus the action name you passed in the browser:
{
"success": true,
"score": 0.9,
"action": "signup",
"challenge_ts": "2026-11-25T06:02:23Z",
"hostname": "example.com"
}
The score goes from 0.0 (very likely a bot) to 1.0 (very likely a good interaction). Google suggests starting with a threshold of 0.5, then adjusting it once you see your real traffic in the admin console.
Always check that action is the one you expect. Action names can only contain letters, numbers, slashes and underscores, and they must not be specific to one user.
Here’s a verification function that checks all of this:
async function verifyRecaptcha(token, expectedAction) {
const response = await fetch(
'https://www.google.com/recaptcha/api/siteverify',
{
method: 'POST',
body: new URLSearchParams({
secret: process.env.RECAPTCHA_SECRET_KEY,
response: token
})
}
)
const result = await response.json()
if (!result.success) {
console.error('reCAPTCHA failed', result['error-codes'])
return false
}
if (result.hostname !== 'example.com') return false
// Only for reCAPTCHA v3
if (expectedAction) {
if (result.action !== expectedAction) return false
if (result.score < 0.5) return false
}
return true
}
Call it from your form handler before you do anything with the data. I show the browser side of the same flow in using reCAPTCHA on an Astro form.
Test keys
For automated tests with reCAPTCHA v2, Google provides public test keys:
- Site key:
6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI - Secret key:
6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
With these, the widget shows no challenge and every verification passes. The widget also shows a warning, so you don’t forget them in production. When I tried them, the response had "hostname": "testkey.google.com", so a hostname check like the one above fails on purpose.
There are no test keys for v3. Google suggests creating a separate key for your test environment, and warns that scores may not be accurate without real traffic.
Free limits
The free version has a quota. Above 1,000,000 calls per month or 1,000 calls per second, Google requires reCAPTCHA Enterprise.
If a v3 key goes over its monthly quota, siteverify may fail open: it returns a fixed score of 0.9 and an “Over free quota” error message. So a perfect-looking score isn’t always a real one.
If you’re tired of CAPTCHAs, Cloudflare Turnstile works with the same idea: a widget in the browser and a verification call from your server.
Want me to talk about your product? You can sponsor this site.
Related posts about js: