Skip to content

Commit

Permalink
fix: Auth header not ignoring other auth schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
tymondesigns committed Apr 27, 2022
1 parent 185d9ad commit 5285281
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Http/Parser/AuthHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ public function parse(Request $request)
{
$header = $request->headers->get($this->header) ?: $this->fromAltHeaders($request);

if ($header) {
$start = strlen($this->prefix);
if ($header !== null) {
$position = strripos($header, $this->prefix);

return trim(substr($header, $start));
if ($position !== false) {
$header = substr($header, $position + strlen($this->prefix));

return trim(
strpos($header, ',') !== false ? strstr($header, ',', true) : $header
);
}
}

return null;
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Http/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ public function it_should_return_the_token_from_the_alt_authorization_headers()
$this->assertTrue($parser->hasToken());
}

/** @test */
public function it_should_ignore_non_bearer_tokens()
{
$request = Request::create('foo', 'POST');
$request->headers->set('Authorization', 'Basic OnBhc3N3b3Jk');

$parser = new Parser($request);

$parser->setChain([
new QueryString,
new InputSource,
new AuthHeaders,
new RouteParams,
]);

$this->assertNull($parser->parseToken());
$this->assertFalse($parser->hasToken());
}

/** @test */
public function it_should_not_strip_trailing_hyphens_from_the_authorization_header()
{
Expand Down

0 comments on commit 5285281

Please sign in to comment.