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

Commit ee81f2a

Browse files
committed
Merge branch 'hotfix/29' into develop
Forward port #29 Conflicts: src/Adapter/Http.php test/Adapter/Http/AuthTest.php
2 parents 0411905 + 9899dd8 commit ee81f2a

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ All notable changes to this project will be documented in this file, in reverse
5151

5252
### Fixed
5353

54-
- Nothing.
54+
- [#29](https://github.com/zendframework/zend-authentication/pull/29) fixes how the HTTP Auth adapter treats credentials,
55+
ensuring it splits only on the first `:` character, and thus allows `:` characters
56+
as part of the password segment of the credential.
5557

5658
## 2.5.3 - 2016-02-29
5759

src/Adapter/Http.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-authentication for the canonical source repository
4+
* @copyright Copyright (c) 2012-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-authentication/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Authentication\Adapter;
@@ -495,23 +493,29 @@ protected function _basicAuth($header)
495493
if (! ctype_print($auth)) {
496494
return $this->challengeClient();
497495
}
496+
497+
$pos = strpos($auth, ':');
498+
if ($pos === false) {
499+
return $this->challengeClient();
500+
}
501+
list($username, $password) = explode(':', $auth, 2);
502+
498503
// Fix for ZF-1515: Now re-challenges on empty username or password
499-
$creds = array_filter(explode(':', $auth));
500-
if (count($creds) != 2) {
504+
if (empty($username) || empty($password)) {
501505
return $this->challengeClient();
502506
}
503507

504-
$result = $this->basicResolver->resolve($creds[0], $this->realm, $creds[1]);
508+
$result = $this->basicResolver->resolve($username, $this->realm, $password);
505509

506510
if ($result instanceof Authentication\Result && $result->isValid()) {
507511
return $result;
508512
}
509513

510514
if (! $result instanceof Authentication\Result
511515
&& ! is_array($result)
512-
&& CryptUtils::compareStrings($result, $creds[1])
516+
&& CryptUtils::compareStrings($result, $password)
513517
) {
514-
$identity = ['username' => $creds[0], 'realm' => $this->realm];
518+
$identity = ['username' => $username, 'realm' => $this->realm];
515519
return new Authentication\Result(Authentication\Result::SUCCESS, $identity);
516520
} elseif (is_array($result)) {
517521
return new Authentication\Result(Authentication\Result::SUCCESS, $result);

src/Adapter/Http/FileResolver.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-authentication for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-authentication/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Authentication\Adapter\Http;
@@ -110,7 +108,7 @@ public function resolve($username, $realm, $password = null)
110108

111109
// No real validation is done on the contents of the password file. The
112110
// assumption is that we trust the administrators to keep it secure.
113-
while (($line = fgetcsv($fp, 512, ':')) !== false) {
111+
while (($line = fgetcsv($fp, 512, ':', '"')) !== false) {
114112
if ($line[0] == $username && $line[1] == $realm) {
115113
$password = $line[2];
116114
fclose($fp);

test/Adapter/Http/AuthTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-authentication for the canonical source repository
4+
* @copyright Copyright (c) 2012-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-authentication/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace ZendTest\Authentication\Adapter\Http;
@@ -15,9 +13,6 @@
1513
use Zend\Http\Request;
1614
use Zend\Http\Response;
1715

18-
/**
19-
* @group Zend_Auth
20-
*/
2116
class AuthTest extends TestCase
2217
{
2318
// @codingStandardsIgnoreStart
@@ -168,6 +163,13 @@ public function testBasicAuthValidCreds()
168163
$this->_checkOK($data);
169164
}
170165

166+
public function testBasicAuthCanValidateCredentialsThatContainAColon()
167+
{
168+
// Attempt Basic Authentication with a valid username and a password that contains a colon
169+
$data = $this->_doAuth('Basic ' . base64_encode('Colon:PasswordWith:Colon'), 'basic');
170+
$this->_checkOK($data);
171+
}
172+
171173
public function testBasicAuthBadCreds()
172174
{
173175
// Ensure that credentials containing invalid characters are treated as

test/Adapter/Http/TestAsset/htbasic.1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Bryce:Test Realm:ThisIsNotMyPassword
22
Mufasa:Test Realm:Circle Of Life
33
Bad Chars:In:Creds
4+
Colon:Test Realm:"PasswordWith:Colon"

0 commit comments

Comments
 (0)