optimizations
This commit is contained in:
@@ -21,6 +21,14 @@ class ForumBotProtectionMiddleware
|
||||
|
||||
public function handle(Request $request, Closure $next, string $action = 'generic'): Response|RedirectResponse|JsonResponse
|
||||
{
|
||||
if (! (bool) config('forum_bot_protection.enabled', true)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($this->shouldBypassForLocalE2E($request)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$assessment = $this->botProtectionService->assess($request, $action);
|
||||
$request->attributes->set('forum_bot_assessment', $assessment);
|
||||
|
||||
@@ -93,4 +101,19 @@ class ForumBotProtectionMiddleware
|
||||
|
||||
return in_array($action, (array) config('forum_bot_protection.captcha.actions', []), true);
|
||||
}
|
||||
|
||||
private function shouldBypassForLocalE2E(Request $request): bool
|
||||
{
|
||||
if (! app()->environment(['local', 'testing'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($request->cookies->get('e2e_bot_bypass') === '1') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$userAgent = strtolower((string) $request->userAgent());
|
||||
|
||||
return str_contains($userAgent, 'headlesschrome') || str_contains($userAgent, 'playwright');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user