Skip to content

Commit 90f50af

Browse files
authored
Merge pull request #100 from internetgalerie/develop
add threshold, reject if score is below threshold
2 parents 2395940 + 69b18ad commit 90f50af

5 files changed

Lines changed: 18 additions & 0 deletions

File tree

Classes/Services/CaptchaService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ public function validateReCaptcha(string $value = ''): array
189189

190190
if ($response['success']) {
191191
$result['verified'] = true;
192+
if (($this->configuration['threshold'] ?? 0) > 0.0) {
193+
// Reject if score is below threshold
194+
if (isset($response['score']) && $response['score'] < $this->configuration['threshold']) {
195+
$result['verified'] = false;
196+
$result['error'] = 'score-threshold-not-met';
197+
}
198+
}
192199
} else {
193200
$result['error'] = (string)(
194201
is_array($response['error-codes']) ?

Configuration/Sets/Recaptcha/labels.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
<trans-unit id="settings.evoweb.recaptcha.enforceCaptcha" resname="settings.evoweb.recaptcha.enforceCaptcha">
5151
<source>Enforcing captcha even in development mode</source>
5252
</trans-unit>
53+
<trans-unit id="settings.evoweb.recaptcha.threshold" resname="settings.evoweb.recaptcha.threshold">
54+
<source>Threshold for score (0.0 - 1.0)</source>
55+
</trans-unit>
5356
<trans-unit id="settings.evoweb.recaptcha.theme" resname="settings.evoweb.recaptcha.theme">
5457
<source>Theme</source>
5558
</trans-unit>

Configuration/Sets/Recaptcha/settings.definitions.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ settings:
4747
default: 0
4848
type: bool
4949
category: recaptcha
50+
evoweb.recaptcha.threshold:
51+
default: 0.5
52+
type: number
53+
category: recaptcha
5054
evoweb.sf-register.captchaId:
5155
default: 'recaptcha'
5256
type: string

Configuration/TypoScript/constants.typoscript

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ plugin.tx_recaptcha {
3030

3131
# cat=plugin.recaptcha//11; type=boolean; label= reCAPTCHA robotMode: If you use a frontend testing tool, which cannot solve the recaptcha
3232
robotMode = 0
33+
34+
# cat=plugin.recaptcha//20; type=string; label= reCAPTCHA threshold: needed score (0.0 - 1.0)
35+
threshold = 0.5
3336
}
3437

3538
plugin.tx_sfregister.settings.captchaId = recaptcha

Configuration/TypoScript/setup.typoscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ plugin.tx_recaptcha {
2121
enforceCaptcha = {$plugin.tx_recaptcha.enforceCaptcha ?? $evoweb.recaptcha.enforceCaptcha}
2222

2323
robotMode = {$plugin.tx_recaptcha.robotMode ?? $evoweb.recaptcha.robotMode}
24+
threshold = {$plugin.tx_recaptcha.threshold ?? $evoweb.recaptcha.threshold}
2425
}
2526

2627

0 commit comments

Comments
 (0)