-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] partitioned option for setcookie/setrawcookie and sessions #12652
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -886,30 +886,31 @@ static PHP_INI_MH(OnUpdateRefererCheck) | |
} | ||
|
||
PHP_INI_BEGIN() | ||
STD_PHP_INI_ENTRY("session.save_path", "", PHP_INI_ALL, OnUpdateSaveDir, save_path, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.name", "PHPSESSID", PHP_INI_ALL, OnUpdateName, session_name, php_ps_globals, ps_globals) | ||
PHP_INI_ENTRY("session.save_handler", "files", PHP_INI_ALL, OnUpdateSaveHandler) | ||
STD_PHP_INI_BOOLEAN("session.auto_start", "0", PHP_INI_PERDIR, OnUpdateBool, auto_start, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.gc_probability", "1", PHP_INI_ALL, OnUpdateSessionGcProbability, gc_probability, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.gc_divisor", "100", PHP_INI_ALL, OnUpdateSessionDivisor,gc_divisor, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.gc_maxlifetime", "1440", PHP_INI_ALL, OnUpdateSessionLong, gc_maxlifetime, php_ps_globals, ps_globals) | ||
PHP_INI_ENTRY("session.serialize_handler", "php", PHP_INI_ALL, OnUpdateSerializer) | ||
STD_PHP_INI_ENTRY("session.cookie_lifetime", "0", PHP_INI_ALL, OnUpdateCookieLifetime,cookie_lifetime, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, OnUpdateSessionStr, cookie_path, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, OnUpdateSessionStr, cookie_domain, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.cookie_secure", "0", PHP_INI_ALL, OnUpdateSessionBool, cookie_secure, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.cookie_httponly", "0", PHP_INI_ALL, OnUpdateSessionBool, cookie_httponly, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cookie_samesite", "", PHP_INI_ALL, OnUpdateSessionStr, cookie_samesite, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.use_cookies", "1", PHP_INI_ALL, OnUpdateSessionBool, use_cookies, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.use_only_cookies", "1", PHP_INI_ALL, OnUpdateUseOnlyCookies, use_only_cookies, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.use_strict_mode", "0", PHP_INI_ALL, OnUpdateSessionBool, use_strict_mode, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, OnUpdateRefererCheck, extern_referer_chk, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, OnUpdateSessionStr, cache_limiter, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cache_expire", "180", PHP_INI_ALL, OnUpdateSessionLong, cache_expire, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.use_trans_sid", "0", PHP_INI_ALL, OnUpdateUseTransSid, use_trans_sid, php_ps_globals, ps_globals) | ||
PHP_INI_ENTRY("session.sid_length", "32", PHP_INI_ALL, OnUpdateSidLength) | ||
PHP_INI_ENTRY("session.sid_bits_per_character", "4", PHP_INI_ALL, OnUpdateSidBits) | ||
STD_PHP_INI_BOOLEAN("session.lazy_write", "1", PHP_INI_ALL, OnUpdateSessionBool, lazy_write, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.save_path", "", PHP_INI_ALL, OnUpdateSaveDir, save_path, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.name", "PHPSESSID", PHP_INI_ALL, OnUpdateName, session_name, php_ps_globals, ps_globals) | ||
PHP_INI_ENTRY("session.save_handler", "files", PHP_INI_ALL, OnUpdateSaveHandler) | ||
STD_PHP_INI_BOOLEAN("session.auto_start", "0", PHP_INI_PERDIR, OnUpdateBool, auto_start, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.gc_probability", "1", PHP_INI_ALL, OnUpdateSessionGcProbability, gc_probability, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.gc_divisor", "100", PHP_INI_ALL, OnUpdateSessionDivisor, gc_divisor, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.gc_maxlifetime", "1440", PHP_INI_ALL, OnUpdateSessionLong, gc_maxlifetime, php_ps_globals, ps_globals) | ||
PHP_INI_ENTRY("session.serialize_handler", "php", PHP_INI_ALL, OnUpdateSerializer) | ||
STD_PHP_INI_ENTRY("session.cookie_lifetime", "0", PHP_INI_ALL, OnUpdateCookieLifetime, cookie_lifetime, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, OnUpdateSessionStr, cookie_path, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, OnUpdateSessionStr, cookie_domain, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.cookie_secure", "0", PHP_INI_ALL, OnUpdateSessionBool, cookie_secure, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.cookie_partitioned", "0", PHP_INI_ALL, OnUpdateSessionBool, cookie_partitioned, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.cookie_httponly", "0", PHP_INI_ALL, OnUpdateSessionBool, cookie_httponly, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cookie_samesite", "", PHP_INI_ALL, OnUpdateSessionStr, cookie_samesite, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.use_cookies", "1", PHP_INI_ALL, OnUpdateSessionBool, use_cookies, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.use_only_cookies", "1", PHP_INI_ALL, OnUpdateUseOnlyCookies, use_only_cookies, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.use_strict_mode", "0", PHP_INI_ALL, OnUpdateSessionBool, use_strict_mode, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, OnUpdateRefererCheck, extern_referer_chk, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, OnUpdateSessionStr, cache_limiter, php_ps_globals, ps_globals) | ||
STD_PHP_INI_ENTRY("session.cache_expire", "180", PHP_INI_ALL, OnUpdateSessionLong, cache_expire, php_ps_globals, ps_globals) | ||
STD_PHP_INI_BOOLEAN("session.use_trans_sid", "0", PHP_INI_ALL, OnUpdateUseTransSid, use_trans_sid, php_ps_globals, ps_globals) | ||
PHP_INI_ENTRY("session.sid_length", "32", PHP_INI_ALL, OnUpdateSidLength) | ||
PHP_INI_ENTRY("session.sid_bits_per_character", "4", PHP_INI_ALL, OnUpdateSidBits) | ||
STD_PHP_INI_BOOLEAN("session.lazy_write", "1", PHP_INI_ALL, OnUpdateSessionBool, lazy_write, php_ps_globals, ps_globals) | ||
|
||
/* Upload progress */ | ||
STD_PHP_INI_BOOLEAN("session.upload_progress.enabled", | ||
|
@@ -1362,6 +1363,12 @@ static zend_result php_session_send_cookie(void) | |
return FAILURE; | ||
} | ||
|
||
/* Check for invalid settings combinations */ | ||
if (UNEXPECTED(PS(cookie_partitioned) && !PS(cookie_secure))) { | ||
php_error_docref(NULL, E_WARNING, "Partitioned session cookie cannot be used without also configuring it as secure"); | ||
return FAILURE; | ||
} | ||
|
||
ZEND_ASSERT(strpbrk(ZSTR_VAL(PS(session_name)), SESSION_FORBIDDEN_CHARS) == NULL); | ||
|
||
/* URL encode id because it might be user supplied */ | ||
|
@@ -1406,6 +1413,10 @@ static zend_result php_session_send_cookie(void) | |
smart_str_appends(&ncookie, COOKIE_SECURE); | ||
} | ||
|
||
if (PS(cookie_partitioned)) { | ||
smart_str_appends(&ncookie, COOKIE_PARTITIONED); | ||
} | ||
|
||
if (PS(cookie_httponly)) { | ||
smart_str_appends(&ncookie, COOKIE_HTTPONLY); | ||
} | ||
|
@@ -1699,6 +1710,7 @@ PHP_FUNCTION(session_set_cookie_params) | |
zend_string *lifetime = NULL, *path = NULL, *domain = NULL, *samesite = NULL; | ||
bool secure = 0, secure_null = 1; | ||
bool httponly = 0, httponly_null = 1; | ||
bool partitioned = false, partitioned_null = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using false/true here is inconsistent with the rest and also with the reassignment in line 1809. This should be unified one way or another. Independent of this, this should probably be fixed once and for all with a tree-wide Coccinelle run. Something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll fix this for ext/session post-merge as a follow up There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Would do this tree-wide (possibly with per-extension commits) to not fix this piecemeal. See also: #19418 (comment) A good opportunity might be right when branching PHP 8.5. |
||
zend_string *ini_name; | ||
zend_result result; | ||
int found = 0; | ||
|
@@ -1766,6 +1778,10 @@ PHP_FUNCTION(session_set_cookie_params) | |
secure = zval_is_true(value); | ||
secure_null = 0; | ||
found++; | ||
} else if (zend_string_equals_literal_ci(key, "partitioned")) { | ||
partitioned = zval_is_true(value); | ||
partitioned_null = 0; | ||
found++; | ||
} else if (zend_string_equals_literal_ci(key, "httponly")) { | ||
httponly = zval_is_true(value); | ||
httponly_null = 0; | ||
|
@@ -1830,6 +1846,15 @@ PHP_FUNCTION(session_set_cookie_params) | |
goto cleanup; | ||
} | ||
} | ||
if (!partitioned_null) { | ||
ini_name = ZSTR_INIT_LITERAL("session.cookie_partitioned", 0); | ||
result = zend_alter_ini_entry_chars(ini_name, partitioned ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); | ||
zend_string_release_ex(ini_name, 0); | ||
if (result == FAILURE) { | ||
RETVAL_FALSE; | ||
goto cleanup; | ||
} | ||
} | ||
if (!httponly_null) { | ||
ini_name = ZSTR_INIT_LITERAL("session.cookie_httponly", 0); | ||
result = zend_alter_ini_entry_chars(ini_name, httponly ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); | ||
|
@@ -1872,6 +1897,7 @@ PHP_FUNCTION(session_get_cookie_params) | |
add_assoc_str(return_value, "path", zend_string_dup(PS(cookie_path), false)); | ||
add_assoc_str(return_value, "domain", zend_string_dup(PS(cookie_domain), false)); | ||
add_assoc_bool(return_value, "secure", PS(cookie_secure)); | ||
add_assoc_bool(return_value, "partitioned", PS(cookie_partitioned)); | ||
add_assoc_bool(return_value, "httponly", PS(cookie_httponly)); | ||
add_assoc_str(return_value, "samesite", zend_string_dup(PS(cookie_samesite), false)); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.