Skip to content

Fix GH-18634: Show warning when saving session if a pipe character is used in one of the $_SESSION keys #18653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ PS_SERIALIZER_ENCODE_FUNC(php)
PHP_VAR_SERIALIZE_DESTROY(var_hash);
smart_str_free(&buf);
fail = true;
php_error_docref(NULL, E_WARNING, "Failed to write session data. Data contains invalid key \"%s\"", ZSTR_VAL(key));
break;
}
smart_str_appendc(&buf, PS_DELIMITER);
Expand Down
13 changes: 13 additions & 0 deletions ext/session/tests/gh18634.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
GH-18634 (Using pipe character in session variable key causes session data to be removed)
--EXTENSIONS--
session
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
session_start();
$_SESSION['foo|bar'] = 'value';
?>
--EXPECT--
Warning: PHP Request Shutdown: Failed to write session data. Data contains invalid key "foo|bar" in Unknown on line 0
14 changes: 14 additions & 0 deletions ext/session/tests/gh18634_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-18634 (Using pipe character in session variable key causes session data to be removed - explicit session write)
--EXTENSIONS--
session
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
session_start();
$_SESSION['foo|bar'] = 'value';
session_write_close()
?>
--EXPECTF--
Warning: session_write_close(): Failed to write session data. Data contains invalid key "foo|bar" in %s on line %d
Loading