Skip to content

Commit 3bb62ee

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #67792: HTTP Authorization schemes are treated as case-sensitive
2 parents 78e1f19 + 23a192d commit 3bb62ee

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

main/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,12 +2591,13 @@ PHPAPI void php_handle_aborted_connection(void)
25912591
PHPAPI int php_handle_auth_data(const char *auth)
25922592
{
25932593
int ret = -1;
2594+
size_t auth_len = auth != NULL ? strlen(auth) : 0;
25942595

2595-
if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) {
2596+
if (auth && auth_len > 0 && zend_binary_strncasecmp(auth, auth_len, "Basic ", sizeof("Basic ")-1, sizeof("Basic ")-1) == 0) {
25962597
char *pass;
25972598
zend_string *user;
25982599

2599-
user = php_base64_decode((const unsigned char*)auth + 6, strlen(auth) - 6);
2600+
user = php_base64_decode((const unsigned char*)auth + 6, auth_len - 6);
26002601
if (user) {
26012602
pass = strchr(ZSTR_VAL(user), ':');
26022603
if (pass) {
@@ -2615,7 +2616,7 @@ PHPAPI int php_handle_auth_data(const char *auth)
26152616
SG(request_info).auth_digest = NULL;
26162617
}
26172618

2618-
if (ret == -1 && auth && auth[0] != '\0' && strncmp(auth, "Digest ", 7) == 0) {
2619+
if (ret == -1 && auth && auth_len > 0 && zend_binary_strncasecmp(auth, auth_len, "Digest ", sizeof("Digest ")-1, sizeof("Digest ")-1) == 0) {
26192620
SG(request_info).auth_digest = estrdup(auth + 7);
26202621
ret = 0;
26212622
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Digest Authentication
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
?>
7+
--FILE--
8+
<?php
9+
include "php_cli_server.inc";
10+
php_cli_server_start('var_dump(!isset($_SERVER["PHP_AUTH_USER"]), !isset($_SERVER["PHP_AUTH_PW"]), $_SERVER["PHP_AUTH_DIGEST"]);');
11+
12+
$host = PHP_CLI_SERVER_HOSTNAME;
13+
$fp = php_cli_server_connect();
14+
15+
if(fwrite($fp, <<<HEADER
16+
GET / HTTP/1.1
17+
Host: {$host}
18+
Authorization: digest username="Mufasa", realm="[email protected]", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop=auth, nc=00000001, cnonce="0a4f113b", response="6629fae49393a05397450978507c4ef1", opaque="5ccc069c403ebaf9f0171e9517f40e41"
19+
20+
21+
HEADER
22+
)) {
23+
fpassthru($fp);
24+
}
25+
26+
?>
27+
--EXPECTF--
28+
HTTP/1.1 200 OK
29+
Host: %s
30+
Date: %s
31+
Connection: close
32+
X-Powered-By: PHP/%s
33+
Content-type: text/html; charset=UTF-8
34+
35+
bool(true)
36+
bool(true)
37+
string(242) "username="Mufasa", realm="[email protected]", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop=auth, nc=00000001, cnonce="0a4f113b", response="6629fae49393a05397450978507c4ef1", opaque="5ccc069c403ebaf9f0171e9517f40e41""

0 commit comments

Comments
 (0)