mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-01 02:41:39 -05:00
Fixed Captcha when on non-enterprise plans
ref BAE-396
This commit is contained in:
parent
ec327badf9
commit
fc5363f07e
2 changed files with 51 additions and 1 deletions
|
@ -45,7 +45,11 @@ class CaptchaService {
|
|||
|
||||
captchaResponse = await hcaptcha.verify(secretKey, req.body.token, req.ip);
|
||||
|
||||
if (captchaResponse.score < scoreThreshold) {
|
||||
if ('score' in captchaResponse && captchaResponse.score < scoreThreshold) {
|
||||
// Using hCaptcha enterprise, so score is present
|
||||
next();
|
||||
} else if (!('score' in captchaResponse) && captchaResponse.success) {
|
||||
// Using regular hCaptcha, so challenge-based
|
||||
next();
|
||||
} else {
|
||||
logging.error(`Blocking request due to high score (${captchaResponse.score})`);
|
||||
|
|
|
@ -91,6 +91,52 @@ describe('CaptchaService', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('Succeeds if no score present, but challenge was successful', function (done) {
|
||||
hcaptcha.verify.resolves({success: true});
|
||||
|
||||
const captchaService = new CaptchaService({
|
||||
enabled: true,
|
||||
scoreThreshold: 0.8,
|
||||
secretKey: 'test-secret'
|
||||
});
|
||||
|
||||
const captchaMiddleware = captchaService.getMiddleware();
|
||||
|
||||
const req = {
|
||||
body: {
|
||||
token: 'test-token'
|
||||
}
|
||||
};
|
||||
|
||||
captchaMiddleware(req, null, (err) => {
|
||||
assert.equal(err, undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fails if no score is present and challenge unsuccessful', function (done) {
|
||||
hcaptcha.verify.resolves({success: false});
|
||||
|
||||
const captchaService = new CaptchaService({
|
||||
enabled: true,
|
||||
scoreThreshold: 0.8,
|
||||
secretKey: 'test-secret'
|
||||
});
|
||||
|
||||
const captchaMiddleware = captchaService.getMiddleware();
|
||||
|
||||
const req = {
|
||||
body: {
|
||||
token: 'test-token'
|
||||
}
|
||||
};
|
||||
|
||||
captchaMiddleware(req, null, (err) => {
|
||||
assert.equal(err.message, 'The server has encountered an error.');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Returns a 400 if no token provided', function (done) {
|
||||
const captchaService = new CaptchaService({
|
||||
enabled: true,
|
||||
|
|
Loading…
Add table
Reference in a new issue