Skip to content

Commit

Permalink
Avoid running string functions when domain is null (#258)
Browse files Browse the repository at this point in the history
Fixes an issue in PHP 8.1 where a request with no `Referer` or `Origin`
header causes a "deprecated" `ErrorException` when `Str::replaceFirst`
attempts to call `strpos` with `null` as the first argument.
  • Loading branch information
dshoreman authored Mar 7, 2021
1 parent 70a82a6 commit 3283515
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Http/Middleware/EnsureFrontendRequestsAreStateful.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public static function fromFrontend($request)
{
$domain = $request->headers->get('referer') ?: $request->headers->get('origin');

if (is_null($domain)) {
return false;
}

$domain = Str::replaceFirst('https://', '', $domain);
$domain = Str::replaceFirst('http://', '', $domain);
$domain = Str::endsWith($domain, '/') ? $domain : "{$domain}/";
Expand Down

0 comments on commit 3283515

Please sign in to comment.