Skip to content

Commit

Permalink
Return 400 when recaptcha example fails (ampproject#20668)
Browse files Browse the repository at this point in the history
  • Loading branch information
torch2424 authored Feb 14, 2019
1 parent 3f0d6c6 commit 893ff3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion build-system/recaptcha-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,18 @@ recaptchaRouter.post(
responseJson[bodyKey] = req.body[bodyKey];
});

res.status(200).json(responseJson);
const containsRecaptchaInResponse = Object.keys(responseJson)
.some(responseJsonKey => {
return responseJsonKey.toLowerCase().includes('recaptcha');
});

if (containsRecaptchaInResponse) {
res.status(200).json(responseJson);
} else {
res.status(400).json({
message: 'Did not include a recaptcha token',
});
}
}
);

Expand Down
6 changes: 3 additions & 3 deletions examples/recaptcha.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ <h1>You searched for: {{term}}</h1>
<div submit-error>
<template type="amp-mustache">
<h1>Error! Please check the JS Console in your dev tools.</h1>
<p>{{error}}</p>
<p>{{message}}</p>
</template>
</div>

Expand Down Expand Up @@ -193,7 +193,7 @@ <h1>You searched for: {{term}}</h1>
<div submit-error>
<template type="amp-mustache">
<h1>Error! Please check the JS Console in your dev tools.</h1>
<p>{{error}}</p>
<p>{{message}}</p>
</template>
</div>

Expand Down Expand Up @@ -305,7 +305,7 @@ <h1>You searched for: {{term}}</h1>
<div submit-error>
<template type="amp-mustache">
<h1>Error! Please check the JS Console in your dev tools.</h1>
<p>{{error}}</p>
<p>{{message}}</p>
</template>
</div>

Expand Down

0 comments on commit 893ff3f

Please sign in to comment.