Skip to content

Commit 0611be4

Browse files
committed
Fix #81727: Don't mangle HTTP variable names that clash with ones that have a specific semantic meaning.
1 parent 198f3f5 commit 0611be4

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3+
29 Sep 2022, PHP 7.4.31
4+
5+
- Core:
6+
. Fixed bug #81727: Don't mangle HTTP variable names that clash with ones
7+
that have a specific semantic meaning. (Derick)
8+
39
09 Jun 2022, PHP 7.4.30
410

511
- mysqlnd:

ext/standard/tests/bug81727.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #81727: $_COOKIE name starting with ..Host/..Secure should be discarded
3+
--COOKIE--
4+
..Host-test=ignore; __Host-test=correct; . Secure-test=ignore; . Elephpant=Awesome;
5+
--FILE--
6+
<?php
7+
var_dump($_COOKIE);
8+
?>
9+
--EXPECT--
10+
array(2) {
11+
["__Host-test"]=>
12+
string(7) "correct"
13+
["__Elephpant"]=>
14+
string(7) "Awesome"
15+
}

main/php_variables.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
115115
}
116116
var_len = p - var;
117117

118+
/* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host- */
119+
if (strncmp(var, "__Host-", sizeof("__Host-")-1) == 0 && strncmp(var_name, "__Host-", sizeof("__Host-")-1) != 0) {
120+
zval_ptr_dtor_nogc(val);
121+
free_alloca(var_orig, use_heap);
122+
return;
123+
}
124+
125+
/* Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
126+
if (strncmp(var, "__Secure-", sizeof("__Secure-")-1) == 0 && strncmp(var_name, "__Secure-", sizeof("__Secure-")-1) != 0) {
127+
zval_ptr_dtor_nogc(val);
128+
free_alloca(var_orig, use_heap);
129+
return;
130+
}
131+
118132
if (var_len==0) { /* empty variable name, or variable name with a space in it */
119133
zval_ptr_dtor_nogc(val);
120134
free_alloca(var_orig, use_heap);

0 commit comments

Comments
 (0)