-
Notifications
You must be signed in to change notification settings - Fork 467
Open
Description
Validation succeeds only if the correct answer is given to the first check() or check_api() call. If a user enters an incorrect value, they cannot try again; instead a new captcha must be generated. I think that is because we use Cache::pull() rather than Cache::get() in the check code:
if (!Cache::pull($this->get_cache_key($key))) {
return false;
}The problem can be illustrated with artisan tinker running this:
$testCaptcha = function(bool $positive) {
echo ">>> Testing Captcha ...\n";
$captcha = app('captcha');
$challenge = (object)$captcha->create(api:true);
$key = $challenge->key;
echo "Challenge Key: {$key}\n";
$ans = implode('', Cache::get('captcha_'.md5($key)));
echo "Answer: $ans\n";
$attempts = $positive ? [ $ans ] : [
"bad-{$ans}",
$ans,
];
foreach ($attempts as $try) {
$label = $try == $ans ? 'correct' : 'incorrect';
echo "Attempting {$label} '{$try}' ... ";
$res = $captcha->check_api($try, $key);
echo json_encode($res), "\n";
}
};
$testCaptcha(true);
$testCaptcha(false);Example output follows:
Psy Shell v0.12.4 (PHP 8.3.13 — cli) by Justin Hileman
>>> Testing Captcha ...
Challenge Key: $2y$12$p7oNGQVf9zp3UxVjfImhz.Hf2RKvEcRuI6/FdWeX2JBuHjMBH89eu
Answer: 410204101
Attempting correct '410204101' ... true
>>> Testing Captcha ...
Challenge Key: $2y$12$luzJOGY3ULHhHx9ZP.W8BeGH.BwXylczwZO8XthleQFwoI2GKrumy
Answer: 906279280
Attempting incorrect 'bad-906279280' ... false
Attempting correct '906279280' ... false
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels