Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit e541416

Browse files
committed
#8 don't authorize if multiple auth header are sent
1 parent 5c812bc commit e541416

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/BasicAccess.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ public function __construct(
5252

5353
public function authenticate(ServerRequestInterface $request) : ?UserInterface
5454
{
55-
$authHeader = $request->getHeader('Authorization');
56-
if (! isset($authHeader[0])) {
55+
$authHeaders = $request->getHeader('Authorization');
56+
57+
if (1 !== count($authHeaders)) {
5758
return null;
5859
}
5960

60-
if (! preg_match('/Basic (?P<credentials>.+)/', $authHeader[0], $match)) {
61+
$authHeader = array_shift($authHeaders);
62+
63+
if (! preg_match('/Basic (?P<credentials>.+)/', $authHeader, $match)) {
6164
return null;
6265
}
6366

test/BasicAccessTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ public function provideInvalidAuthenticationHeader(): array
166166
'only-pile-of-poo-emoji' => [['💩']],
167167
'basic-prefix-without-content' => [['Basic ']],
168168
'only-basic' => [['Basic']],
169+
'multiple-auth-headers' => [
170+
[
171+
['Basic ' . base64_encode('Aladdin:OpenSesame')],
172+
['Basic ' . base64_encode('Aladdin:OpenSesame')],
173+
],
174+
],
169175
];
170176
}
171177

0 commit comments

Comments
 (0)