Skip to content

Commit 5285281

Browse files
committed
fix: Auth header not ignoring other auth schemes
1 parent 185d9ad commit 5285281

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/Http/Parser/AuthHeaders.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,19 @@ public function parse(Request $request)
5151
{
5252
$header = $request->headers->get($this->header) ?: $this->fromAltHeaders($request);
5353

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

57-
return trim(substr($header, $start));
57+
if ($position !== false) {
58+
$header = substr($header, $position + strlen($this->prefix));
59+
60+
return trim(
61+
strpos($header, ',') !== false ? strstr($header, ',', true) : $header
62+
);
63+
}
5864
}
65+
66+
return null;
5967
}
6068

6169
/**

tests/Http/ParserTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,25 @@ public function it_should_return_the_token_from_the_alt_authorization_headers()
108108
$this->assertTrue($parser->hasToken());
109109
}
110110

111+
/** @test */
112+
public function it_should_ignore_non_bearer_tokens()
113+
{
114+
$request = Request::create('foo', 'POST');
115+
$request->headers->set('Authorization', 'Basic OnBhc3N3b3Jk');
116+
117+
$parser = new Parser($request);
118+
119+
$parser->setChain([
120+
new QueryString,
121+
new InputSource,
122+
new AuthHeaders,
123+
new RouteParams,
124+
]);
125+
126+
$this->assertNull($parser->parseToken());
127+
$this->assertFalse($parser->hasToken());
128+
}
129+
111130
/** @test */
112131
public function it_should_not_strip_trailing_hyphens_from_the_authorization_header()
113132
{

0 commit comments

Comments
 (0)