Skip to content

Commit d9d4c05

Browse files
committed
Fix silent failure mode when recaptcha is enabled
1 parent 926b5ac commit d9d4c05

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

app/Http/Middleware/VerifyReCaptcha.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
use stdClass;
77
use GuzzleHttp\Client;
88
use Illuminate\Http\Request;
9+
use Illuminate\Http\Response;
910
use Pterodactyl\Events\Auth\FailedCaptcha;
1011
use Illuminate\Contracts\Config\Repository;
12+
use Illuminate\Contracts\Events\Dispatcher;
13+
use Symfony\Component\HttpKernel\Exception\HttpException;
1114

1215
class VerifyReCaptcha
1316
{
@@ -16,14 +19,21 @@ class VerifyReCaptcha
1619
*/
1720
private $config;
1821

22+
/**
23+
* @var \Illuminate\Contracts\Events\Dispatcher
24+
*/
25+
private $dispatcher;
26+
1927
/**
2028
* VerifyReCaptcha constructor.
2129
*
30+
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
2231
* @param \Illuminate\Contracts\Config\Repository $config
2332
*/
24-
public function __construct(Repository $config)
33+
public function __construct(Dispatcher $dispatcher, Repository $config)
2534
{
2635
$this->config = $config;
36+
$this->dispatcher = $dispatcher;
2737
}
2838

2939
/**
@@ -57,10 +67,15 @@ public function handle($request, Closure $next)
5767
}
5868
}
5969

60-
// Emit an event and return to the previous view with an error (only the captcha error will be shown!)
61-
event(new FailedCaptcha($request->ip(), (! isset($result) ?: object_get($result, 'hostname'))));
70+
$this->dispatcher->dispatch(
71+
new FailedCaptcha(
72+
$request->ip(), ! empty($result) ? ($result->hostname ?? null) : null
73+
)
74+
);
6275

63-
return redirect()->back()->withErrors(['g-recaptcha-response' => trans('strings.captcha_invalid')])->withInput();
76+
throw new HttpException(
77+
Response::HTTP_BAD_REQUEST, 'Failed to validate reCAPTCHA data.'
78+
);
6479
}
6580

6681
/**

0 commit comments

Comments
 (0)