Skip to content

Commit 78c2deb

Browse files
smalyshevcmb69
authored andcommitted
Do not decode cookie names anymore
(cherry picked from commit 95e1a41)
1 parent de777c8 commit 78c2deb

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP NEWS
66
. Fixed bug #80048 (Bug #69100 has not been fixed for Windows). (cmb)
77
. Fixed bug #80049 (Memleak when coercing integers to string via variadic
88
argument). (Nikita)
9+
. Fixed bug ##79699 (PHP parses encoded cookie names so malicious `__Host-`
10+
cookies can be sent). (CVE-2020-7070) (Stas)
911

1012
- Calendar:
1113
. Fixed bug #80007 (Potential type confusion in unixtojd() parameter parsing).

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ Reflection:
151151
. Reflection export to string now uses `int` and `bool` instead of `integer`
152152
and `boolean`.
153153

154+
SAPI:
155+
. Starting with 7.3.24, incoming cookie names are not url-decoded. This was never
156+
required by the standard, outgoing cookie names aren't encoded and this leads
157+
to security issues (CVE-2020-7070).
158+
154159
SPL:
155160
. If an SPL autoloader throws an exception, following autoloaders will not be
156161
executed. Previously all autoloaders were executed and exceptions were

main/php_variables.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
501501
size_t new_val_len;
502502

503503
*val++ = '\0';
504-
php_url_decode(var, strlen(var));
504+
if (arg != PARSE_COOKIE) {
505+
php_url_decode(var, strlen(var));
506+
}
505507
val_len = php_url_decode(val, strlen(val));
506508
val = estrndup(val, val_len);
507509
if (sapi_module.input_filter(arg, var, &val, val_len, &new_val_len)) {
@@ -512,7 +514,9 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
512514
size_t val_len;
513515
size_t new_val_len;
514516

515-
php_url_decode(var, strlen(var));
517+
if (arg != PARSE_COOKIE) {
518+
php_url_decode(var, strlen(var));
519+
}
516520
val_len = 0;
517521
val = estrndup("", val_len);
518522
if (sapi_module.input_filter(arg, var, &val, val_len, &new_val_len)) {

tests/basic/022.phpt

Lines changed: 7 additions & 3 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 22 additions & 0 deletions
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)