Skip to content

Commit c4dc080

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Update UPGRADING Update NEWS & UPGRADING Do not decode cookie names anymore Fix bug #79601 (Wrong ciphertext/tag in AES-CCM encryption for a 12 bytes IV)
2 parents 626705f + a9e4321 commit c4dc080

File tree

8 files changed

+92
-27
lines changed

8 files changed

+92
-27
lines changed

ext/openssl/openssl.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -6521,11 +6521,6 @@ static int php_openssl_validate_iv(char **piv, size_t *piv_len, size_t iv_requir
65216521
{
65226522
char *iv_new;
65236523

6524-
/* Best case scenario, user behaved */
6525-
if (*piv_len == iv_required_len) {
6526-
return SUCCESS;
6527-
}
6528-
65296524
if (mode->is_aead) {
65306525
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_ivlen_flag, *piv_len, NULL) != 1) {
65316526
php_error_docref(NULL, E_WARNING, "Setting of IV length for AEAD mode failed");
@@ -6534,6 +6529,11 @@ static int php_openssl_validate_iv(char **piv, size_t *piv_len, size_t iv_requir
65346529
return SUCCESS;
65356530
}
65366531

6532+
/* Best case scenario, user behaved */
6533+
if (*piv_len == iv_required_len) {
6534+
return SUCCESS;
6535+
}
6536+
65376537
iv_new = ecalloc(1, iv_required_len + 1);
65386538

65396539
if (*piv_len == 0) {

ext/openssl/tests/cipher_tests.inc

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
<?php
22
$php_openssl_cipher_tests = array(
3+
'aes-128-ccm' => array(
4+
array(
5+
'key' => '404142434445464748494a4b4c4d4e4f',
6+
'iv' => '1011121314151617',
7+
'aad' => '000102030405060708090a0b0c0d0e0f',
8+
'tag' => '1fc64fbfaccd',
9+
'pt' => '202122232425262728292a2b2c2d2e2f',
10+
'ct' => 'd2a1f0e051ea5f62081a7792073d593d',
11+
),
12+
array(
13+
'key' => '404142434445464748494a4b4c4d4e4f',
14+
'iv' => '101112131415161718191a1b',
15+
'aad' => '000102030405060708090a0b0c0d0e0f' .
16+
'10111213',
17+
'tag' => '484392fbc1b09951',
18+
'pt' => '202122232425262728292a2b2c2d2e2f' .
19+
'3031323334353637',
20+
'ct' => 'e3b201a9f5b71a7a9b1ceaeccd97e70b' .
21+
'6176aad9a4428aa5',
22+
),
23+
),
324
'aes-256-ccm' => array(
425
array(
526
'key' => '1bde3251d41a8b5ea013c195ae128b21' .

ext/openssl/tests/openssl_decrypt_ccm.phpt

+14-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ if (!in_array('aes-256-ccm', openssl_get_cipher_methods()))
1010
--FILE--
1111
<?php
1212
require_once __DIR__ . "/cipher_tests.inc";
13-
$method = 'aes-256-ccm';
14-
$tests = openssl_get_cipher_tests($method);
13+
$methods = ['aes-128-ccm', 'aes-256-ccm'];
1514

16-
foreach ($tests as $idx => $test) {
17-
echo "TEST $idx\n";
18-
$pt = openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
19-
$test['iv'], $test['tag'], $test['aad']);
20-
var_dump($test['pt'] === $pt);
15+
foreach ($methods as $method) {
16+
$tests = openssl_get_cipher_tests($method);
17+
foreach ($tests as $idx => $test) {
18+
echo "$method - TEST $idx\n";
19+
$pt = openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
20+
$test['iv'], $test['tag'], $test['aad']);
21+
var_dump($test['pt'] === $pt);
22+
}
2123
}
2224

2325
// no IV
@@ -32,7 +34,11 @@ var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
3234

3335
?>
3436
--EXPECTF--
35-
TEST 0
37+
aes-128-ccm - TEST 0
38+
bool(true)
39+
aes-128-ccm - TEST 1
40+
bool(true)
41+
aes-256-ccm - TEST 0
3642
bool(true)
3743

3844
Warning: openssl_decrypt(): Setting of IV length for AEAD mode failed in %s on line %d

ext/openssl/tests/openssl_encrypt_ccm.phpt

+17-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ if (!in_array('aes-256-ccm', openssl_get_cipher_methods()))
1010
--FILE--
1111
<?php
1212
require_once __DIR__ . "/cipher_tests.inc";
13-
$method = 'aes-256-ccm';
14-
$tests = openssl_get_cipher_tests($method);
13+
$methods = ['aes-128-ccm', 'aes-256-ccm'];
1514

16-
foreach ($tests as $idx => $test) {
17-
echo "TEST $idx\n";
18-
$ct = openssl_encrypt($test['pt'], $method, $test['key'], OPENSSL_RAW_DATA,
19-
$test['iv'], $tag, $test['aad'], strlen($test['tag']));
20-
var_dump($test['ct'] === $ct);
21-
var_dump($test['tag'] === $tag);
15+
foreach ($methods as $method) {
16+
$tests = openssl_get_cipher_tests($method);
17+
foreach ($tests as $idx => $test) {
18+
echo "$method - TEST $idx\n";
19+
$ct = openssl_encrypt($test['pt'], $method, $test['key'], OPENSSL_RAW_DATA,
20+
$test['iv'], $tag, $test['aad'], strlen($test['tag']));
21+
var_dump($test['ct'] === $ct);
22+
var_dump($test['tag'] === $tag);
23+
}
2224
}
2325

2426
// Empty IV error
@@ -32,7 +34,13 @@ var_dump(strlen($tag));
3234
var_dump(openssl_encrypt('data', $method, 'password', 0, str_repeat('x', 16), $tag, '', 1024));
3335
?>
3436
--EXPECTF--
35-
TEST 0
37+
aes-128-ccm - TEST 0
38+
bool(true)
39+
bool(true)
40+
aes-128-ccm - TEST 1
41+
bool(true)
42+
bool(true)
43+
aes-256-ccm - TEST 0
3644
bool(true)
3745
bool(true)
3846

main/php_variables.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
514514
}
515515

516516
val = estrndup(val, val_len);
517-
php_url_decode(var, strlen(var));
517+
if (arg != PARSE_COOKIE) {
518+
php_url_decode(var, strlen(var));
519+
}
518520
if (sapi_module.input_filter(arg, var, &val, val_len, &new_val_len)) {
519521
php_register_variable_safe(var, val, new_val_len, &array);
520522
}

tests/basic/022.phpt

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cookie1=val1 ; cookie2=val2%20; cookie3=val 3.; cookie 4= value 4 %3B; cookie1=
1010
var_dump($_COOKIE);
1111
?>
1212
--EXPECT--
13-
array(10) {
13+
array(12) {
1414
["cookie1"]=>
1515
string(6) "val1 "
1616
["cookie2"]=>
@@ -19,11 +19,15 @@ array(10) {
1919
string(6) "val 3."
2020
["cookie_4"]=>
2121
string(10) " value 4 ;"
22+
["%20cookie1"]=>
23+
string(6) "ignore"
24+
["+cookie1"]=>
25+
string(6) "ignore"
2226
["cookie__5"]=>
2327
string(7) " value"
24-
["cookie_6"]=>
28+
["cookie%206"]=>
2529
string(3) "þæö"
26-
["cookie_7"]=>
30+
["cookie+7"]=>
2731
string(0) ""
2832
["$cookie_8"]=>
2933
string(0) ""

tests/basic/023.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ c o o k i e=value; c o o k i e= v a l u e ;;c%20o+o k+i%20e=v;name="value","valu
1010
var_dump($_COOKIE);
1111
?>
1212
--EXPECT--
13-
array(3) {
13+
array(4) {
1414
["c_o_o_k_i_e"]=>
1515
string(5) "value"
16+
["c%20o+o_k+i%20e"]=>
17+
string(1) "v"
1618
["name"]=>
1719
string(24) ""value","value",UEhQIQ=="
1820
["UEhQIQ"]=>

tests/basic/bug79699.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Cookies Security Bug
3+
--INI--
4+
max_input_vars=1000
5+
filter.default=unsafe_raw
6+
--COOKIE--
7+
__%48ost-evil=evil; __Host-evil=good; %66oo=baz;foo=bar
8+
--FILE--
9+
<?php
10+
var_dump($_COOKIE);
11+
?>
12+
--EXPECT--
13+
array(4) {
14+
["__%48ost-evil"]=>
15+
string(4) "evil"
16+
["__Host-evil"]=>
17+
string(4) "good"
18+
["%66oo"]=>
19+
string(3) "baz"
20+
["foo"]=>
21+
string(3) "bar"
22+
}

0 commit comments

Comments
 (0)