Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ PHP NEWS
- Session:
. Fixed bug 71162 (updateTimestamp never called when session data is empty).
(Girgias)
. Null bytes in session.cookie_path, session.cookie_domain, and
session.cache_limiter are now rejected with a warning. (jorgsowa)

- Soap:
. Soap::__setCookie() when cookie name is a digit is now not stored and
Expand Down
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ PHP 8.6 UPGRADE NOTES
argument value is passed.

- Session:
. Setting session.cookie_path, session.cookie_domain, or session.cache_limiter
to a value containing null bytes now emits a warning and leaves the setting
unchanged. Previously, null bytes were silently accepted: for cookie_path and
cookie_domain this caused the SAPI to drop the Set-Cookie header; for
cache_limiter the value was silently truncated at the null byte.
. A ValueError is not thrown if $name is a string containing null bytes in
session_module_name().
. session_encode() now returns an empty string instead of false for empty
Expand Down
7 changes: 7 additions & 0 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,13 @@ static PHP_INI_MH(OnUpdateSessionStr)
SESSION_CHECK_ACTIVE_STATE;
SESSION_CHECK_OUTPUT_STATE;

if (new_value && zend_str_has_nul_byte(new_value)) {
if (stage != ZEND_INI_STAGE_DEACTIVATE) {
php_error_docref(NULL, E_WARNING, "\"%s\" must not contain null bytes", ZSTR_VAL(entry->name));
}
return FAILURE;
}

return OnUpdateStr(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
}

Expand Down
37 changes: 37 additions & 0 deletions ext/session/tests/session_str_settings_null_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
session.cookie_path, session.cookie_domain, and session.cache_limiter must not contain null bytes
--EXTENSIONS--
session
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php

ob_start();

var_dump(ini_set('session.cookie_path', "/path\0evil"));
var_dump(ini_set('session.cookie_domain', "example\0evil.com"));
var_dump(ini_set('session.cache_limiter', "nocache\0evil"));

var_dump(session_set_cookie_params(0, "/path\0evil"));
var_dump(session_set_cookie_params(0, null, "example\0evil.com"));

ob_end_flush();
echo "Done";
?>
--EXPECTF--
Warning: ini_set(): "session.cookie_path" must not contain null bytes in %s on line %d
bool(false)

Warning: ini_set(): "session.cookie_domain" must not contain null bytes in %s on line %d
bool(false)

Warning: ini_set(): "session.cache_limiter" must not contain null bytes in %s on line %d
bool(false)

Warning: session_set_cookie_params(): "session.cookie_path" must not contain null bytes in %s on line %d
bool(false)

Warning: session_set_cookie_params(): "session.cookie_domain" must not contain null bytes in %s on line %d
bool(false)
Done
Loading