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

Commit b728474

Browse files
committed
Merge branch 'hotfix/29'
Close #29
2 parents c04af86 + 9899dd8 commit b728474

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ All notable changes to this project will be documented in this file, in reverse
77
### Added
88

99
- [#9](https://github.com/zendframework/zend-authentication/pull/9) adds and
10-
publishes documentation to https://zendframework.github.io/zend-authentication/
10+
publishes documentation to https://docs.zendframework.com/zend-authentication/
11+
12+
### Changed
13+
14+
- Nothing.
1115

1216
### Deprecated
1317

@@ -19,7 +23,9 @@ All notable changes to this project will be documented in this file, in reverse
1923

2024
### Fixed
2125

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

2430
## 2.5.3 - 2016-02-29
2531

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;
@@ -487,23 +485,29 @@ protected function _basicAuth($header)
487485
if (!ctype_print($auth)) {
488486
return $this->challengeClient();
489487
}
488+
489+
$pos = strpos($auth, ':');
490+
if ($pos === false) {
491+
return $this->challengeClient();
492+
}
493+
list($username, $password) = explode(':', $auth, 2);
494+
490495
// Fix for ZF-1515: Now re-challenges on empty username or password
491-
$creds = array_filter(explode(':', $auth));
492-
if (count($creds) != 2) {
496+
if (empty($username) || empty($password)) {
493497
return $this->challengeClient();
494498
}
495499

496-
$result = $this->basicResolver->resolve($creds[0], $this->realm, $creds[1]);
500+
$result = $this->basicResolver->resolve($username, $this->realm, $password);
497501

498502
if ($result instanceof Authentication\Result && $result->isValid()) {
499503
return $result;
500504
}
501505

502506
if (!$result instanceof Authentication\Result
503507
&& !is_array($result)
504-
&& CryptUtils::compareStrings($result, $creds[1])
508+
&& CryptUtils::compareStrings($result, $password)
505509
) {
506-
$identity = ['username' => $creds[0], 'realm' => $this->realm];
510+
$identity = ['username' => $username, 'realm' => $this->realm];
507511
return new Authentication\Result(Authentication\Result::SUCCESS, $identity);
508512
} elseif (is_array($result)) {
509513
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;
@@ -14,9 +12,6 @@
1412
use Zend\Http\Request;
1513
use Zend\Http\Response;
1614

17-
/**
18-
* @group Zend_Auth
19-
*/
2015
class AuthTest extends \PHPUnit_Framework_TestCase
2116
{
2217
/**
@@ -165,6 +160,13 @@ public function testBasicAuthValidCreds()
165160
$this->_checkOK($data);
166161
}
167162

163+
public function testBasicAuthCanValidateCredentialsThatContainAColon()
164+
{
165+
// Attempt Basic Authentication with a valid username and a password that contains a colon
166+
$data = $this->_doAuth('Basic ' . base64_encode('Colon:PasswordWith:Colon'), 'basic');
167+
$this->_checkOK($data);
168+
}
169+
168170
public function testBasicAuthBadCreds()
169171
{
170172
// 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)