Skip to content

Commit e4df09c

Browse files
feat(captcha): Use redirect when captcha is resolved
1 parent dfb8287 commit e4df09c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/AbstractBounce.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,14 @@ protected function handleCaptchaResolutionForm(string $ip)
214214
$this->getPostedVariable('phrase'),
215215
$ip)) {
216216
// User has correctly fill the captcha
217-
218217
$this->setSessionVariable('crowdsec_captcha_has_to_be_resolved', false);
219218
$this->unsetSessionVariable('crowdsec_captcha_phrase_to_guess');
220219
$this->unsetSessionVariable('crowdsec_captcha_inline_image');
221220
$this->unsetSessionVariable('crowdsec_captcha_resolution_failed');
221+
$redirect = $this->getSessionVariable('crowdsec_captcha_resolution_redirect')??'/';
222+
$this->unsetSessionVariable('crowdsec_captcha_resolution_redirect');
223+
header("Location: $redirect");
224+
exit(0);
222225
} else {
223226
// The user failed to resolve the captcha.
224227
$this->setSessionVariable('crowdsec_captcha_resolution_failed', true);
@@ -237,6 +240,9 @@ protected function handleCaptchaRemediation($ip)
237240
$this->storeNewCaptchaCoupleInSession();
238241
$this->setSessionVariable('crowdsec_captcha_has_to_be_resolved', true);
239242
$this->setSessionVariable('crowdsec_captcha_resolution_failed', false);
243+
$this->setSessionVariable('crowdsec_captcha_resolution_redirect', 'POST' === $this->getHttpMethod() &&
244+
!empty($_SERVER['HTTP_REFERER']) ?
245+
$_SERVER['HTTP_REFERER'] : $_SERVER['REQUEST_URI']);
240246
}
241247

242248
// Display captcha page if this is required.

0 commit comments

Comments
 (0)