[PHP-CVS] [php-src] master: Merge branch 'PHP-8.5'
[email protected] (Ilia Alshanetsky)
| Newsgroups | php.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Ilia Alshanetsky (iliaal)
Date: 2026-08-23T13:03:35-04:00
Commit: https://github.com/php/php-src/commit/c96900ee74a4ea90c85597a35c6ef6d83bb46d78
Raw diff: https://github.com/php/php-src/commit/c96900ee74a4ea90c85597a35c6ef6d83bb46d78.diff
Merge branch 'PHP-8.5'
* PHP-8.5:
ext/session: report a rejected session cookie header
Changed paths:
A ext/session/tests/session_start_cookie_header_rejected.phpt
M ext/session/session.c
Diff:
diff --git a/ext/session/session.c b/ext/session/session.c
index 6a9f2b355c12..21545ecc01ba 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -1482,10 +1482,10 @@ static zend_result php_session_send_cookie(void)
php_session_remove_cookie(); /* remove already sent session ID cookie */
/* 'replace' must be 0 here, else a previous Set-Cookie
header, probably sent with setcookie() will be replaced! */
- sapi_add_header_ex(estrndup(ZSTR_VAL(ncookie.s), ZSTR_LEN(ncookie.s)), ZSTR_LEN(ncookie.s), false, false);
+ zend_result result = sapi_add_header_ex(estrndup(ZSTR_VAL(ncookie.s), ZSTR_LEN(ncookie.s)), ZSTR_LEN(ncookie.s), false, false);
smart_str_free(&ncookie);
- return SUCCESS;
+ return result;
}
PHPAPI const ps_module *_php_find_ps_module(const char *name)
diff --git a/ext/session/tests/session_start_cookie_header_rejected.phpt b/ext/session/tests/session_start_cookie_header_rejected.phpt
new file mode 100644
index 000000000000..6c3e3b78a3b5
--- /dev/null
+++ b/ext/session/tests/session_start_cookie_header_rejected.phpt
@@ -0,0 +1,28 @@
+--TEST--
+session_start() when the SAPI rejects the session cookie header
+--INI--
+session.save_handler=files
+session.name=PHPSESSID
+session.gc_probability=0
+--EXTENSIONS--
+session
+--FILE--
+<?php
+
+ob_start();
+
+set_error_handler(function (int $errno, string $errstr): bool {
+ echo "handler: ", $errstr, PHP_EOL;
+ return true;
+});
+
+session_set_cookie_params(['path' => "/\r\nX-Injected: yes"]);
+
+var_dump(session_start());
+var_dump(session_status() === PHP_SESSION_NONE);
+
+?>
+--EXPECT--
+handler: Header may not contain more than a single header, new line detected
+bool(false)
+bool(true)