Skip to content

Commit f92b09c

Browse files
committed
session: Raise a warning if session variable key contains pipe character
Fixes #18634
1 parent 910aeaa commit f92b09c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

ext/session/session.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ PS_SERIALIZER_ENCODE_FUNC(php) /* {{{ */
994994
if (memchr(ZSTR_VAL(key), PS_DELIMITER, ZSTR_LEN(key))) {
995995
PHP_VAR_SERIALIZE_DESTROY(var_hash);
996996
smart_str_free(&buf);
997+
php_error_docref(NULL, E_WARNING, "Failed to write session data. Data contains invalid key \"%s\".", ZSTR_VAL(key));
997998
return NULL;
998999
}
9991000
smart_str_appendc(&buf, PS_DELIMITER);

ext/session/tests/gh18634.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-18634 (Using pipe character in session variable key causes session data to be removed)
3+
--INI--
4+
--EXTENSIONS--
5+
session
6+
--SKIPIF--
7+
<?php include('skipif.inc'); ?>
8+
--FILE--
9+
<?php
10+
ob_start();
11+
session_start();
12+
$_SESSION['foo|bar'] = 'value';
13+
ob_end_clean();
14+
?>
15+
--EXPECTF--
16+
Warning: PHP Request Shutdown: Failed to write session data. Data contains invalid key "foo|bar". in Unknown on line 0

0 commit comments

Comments
 (0)