Skip to content

Commit 042a975

Browse files
authored
ext/session: Fix GH-18634 (#18653)
Show warning when saving session if a pipe character is used in one of the $_SESSION keys Fixes #18634
1 parent 462fd4d commit 042a975

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ PHP 8.5 UPGRADE NOTES
101101
. A ValueError is now thrown when trying to set a cursor name that is too
102102
long on a PDOStatement resulting from the Firebird driver.
103103

104+
- Session:
105+
. Attempting to write session data where $_SESSION has a key containing
106+
the pipe character will now emit a warning instead of silently failing.
107+
104108
- SimpleXML:
105109
. Passing an XPath expression that returns something other than a node set
106110
to SimpleXMLElement::xpath() will now emit a warning and return false,

ext/session/session.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ PS_SERIALIZER_ENCODE_FUNC(php)
10591059
PHP_VAR_SERIALIZE_DESTROY(var_hash);
10601060
smart_str_free(&buf);
10611061
fail = true;
1062+
php_error_docref(NULL, E_WARNING, "Failed to write session data. Data contains invalid key \"%s\"", ZSTR_VAL(key));
10621063
break;
10631064
}
10641065
smart_str_appendc(&buf, PS_DELIMITER);

ext/session/tests/gh18634.phpt

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

ext/session/tests/gh18634_2.phpt

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

0 commit comments

Comments
 (0)