10000 merged branch shouze/fix/auth-digest (PR #8952) · symfony/symfony@1086faf · GitHub
[go: up one dir, main page]

Skip to content

Commit 1086faf

Browse files
committed
merged branch shouze/fix/auth-digest (PR #8952)
This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #8952). Discussion ---------- [HttpFoundation] Fixing broken http auth digest in some circumstances. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | can be refered in issue #1813 | License | MIT | Doc PR | n/a With some apache + php-fpm setup we need to set ```PHP_AUTH_DIGEST``` value if not already setted in GLOBAL vars. Added some unit tests too. Commits ------- 9fc994b [HttpFoundation] Fixing broken http auth digest in some circumstances (php-fpm + apache).
2 parents 535cf50 + e75d284 commit 1086faf

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/Symfony/Component/HttpFoundation/ServerBag.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,26 @@ public function getHeaders()
6363
$authorizationHeader = $this->parameters['REDIRECT_HTTP_AUTHORIZATION'];
6464
}
6565

66-
// Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic
67-
if ((null !== $authorizationHeader) && (0 === stripos($authorizationHeader, 'basic'))) {
68-
$exploded = explode(':', base64_decode(substr($authorizationHeader, 6)));
69-
if (count($exploded) == 2) {
70-
list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
66+
if ((null !== $authorizationHeader)) {
67+
if ((0 === stripos($authorizationHeader, 'basic'))) {
68+
// Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic
69+
$exploded = explode(':', base64_decode(substr($authorizationHeader, 6)));
70+
if (count($exploded) == 2) {
71+
list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
72+
}
73+
} elseif (empty($this->parameters['PHP_AUTH_DIGEST']) && (0 === stripos($authorizationHeader, 'digest'))) {
74+
// In some circumstances PHP_AUTH_DIGEST needs to be set
75+
$headers['PHP_AUTH_DIGEST'] = $authorizationHeader;
76+
$this->parameters['PHP_AUTH_DIGEST'] = $authorizationHeader;
7177
}
7278
}
7379
}
7480

7581
// PHP_AUTH_USER/PHP_AUTH_PW
7682
if (isset($headers['PHP_AUTH_USER'])) {
7783
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
84+
} elseif (isset($headers['PHP_AUTH_DIGEST'])) {
85+
$headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
7886
}
7987

8088
return $headers;

src/Symfony/Component/HttpFoundation/Tests/ServerBagTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ public function testHttpBasicAuthWithPhpCgiEmptyPassword()
8989
), $bag->getHeaders());
9090
}
9191

92+
public function testHttpDigestAuthWithPhpCgi()
93+
{
94+
$digest = 'Digest username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"';
95+
$bag = new ServerBag(array('HTTP_AUTHORIZATION' => $digest));
96+
97+
$this->assertEquals(array(
98+
'AUTHORIZATION' => $digest,
99+
'PHP_AUTH_DIGEST' => $digest,
100+
), $bag->getHeaders());
101+
}
102+
103+
public function testHttpDigestAuthWithPhpCgiRedirect()
104+
{
105+
$digest = 'Digest username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"';
106+
$bag = new ServerBag(array('REDIRECT_HTTP_AUTHORIZATION' => $digest));
107+
108+
$this->assertEquals(array(
109+
'AUTHORIZATION' => $digest,
110+
'PHP_AUTH_DIGEST' => $digest,
111+
), $bag->getHeaders());
112+
}
113+
92114
public function testOAuthBearerAuth()
93115
{
94116
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';

0 commit comments

Comments
 (0)
0