Skip to content

Commit

Permalink
Merge pull request #139 from rjchauhan/2.x
Browse files Browse the repository at this point in the history
[2.x] 419 Exception with requests without referrer
  • Loading branch information
taylorotwell authored May 11, 2020
2 parents 0c76899 + ca5b442 commit 8efcb0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Http/Middleware/EnsureFrontendRequestsAreStateful.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public static function fromFrontend($request)

$referer = Str::replaceFirst('http://', '', $referer);

return Str::startsWith($referer, config('sanctum.stateful', [])) ||
Str::is(config('sanctum.stateful', []), $referer);
$stateful = array_filter(config('sanctum.stateful', []));

return Str::startsWith($referer, $stateful) ||
Str::is($stateful, $referer);
}
}
9 changes: 9 additions & 0 deletions tests/EnsureFrontendRequestsAreStatefulTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public function test_wildcard_matching()
$this->assertTrue(EnsureFrontendRequestsAreStateful::fromFrontend($request));
}

public function test_requests_are_not_stateful_without_referer()
{
$this->app['config']->set('sanctum.stateful', ['']);

$request = Request::create('/');

$this->assertFalse(EnsureFrontendRequestsAreStateful::fromFrontend($request));
}

protected function getPackageProviders($app)
{
return [SanctumServiceProvider::class];
Expand Down

0 comments on commit 8efcb0b

Please sign in to comment.