@@ -898,6 +898,7 @@ PHP_INI_BEGIN()
898898 STD_PHP_INI_ENTRY ("session.cookie_path" , "/" , PHP_INI_ALL , OnUpdateSessionStr , cookie_path , php_ps_globals , ps_globals )
899899 STD_PHP_INI_ENTRY ("session.cookie_domain" , "" , PHP_INI_ALL , OnUpdateSessionStr , cookie_domain , php_ps_globals , ps_globals )
900900 STD_PHP_INI_BOOLEAN ("session.cookie_secure" , "0" , PHP_INI_ALL , OnUpdateSessionBool , cookie_secure , php_ps_globals , ps_globals )
901+ STD_PHP_INI_BOOLEAN ("session.cookie_partitioned" ,"0" , PHP_INI_ALL , OnUpdateSessionBool , cookie_partitioned , php_ps_globals , ps_globals )
901902 STD_PHP_INI_BOOLEAN ("session.cookie_httponly" , "0" , PHP_INI_ALL , OnUpdateSessionBool , cookie_httponly , php_ps_globals , ps_globals )
902903 STD_PHP_INI_ENTRY ("session.cookie_samesite" , "" , PHP_INI_ALL , OnUpdateSessionStr , cookie_samesite , php_ps_globals , ps_globals )
903904 STD_PHP_INI_BOOLEAN ("session.use_cookies" , "1" , PHP_INI_ALL , OnUpdateSessionBool , use_cookies , php_ps_globals , ps_globals )
@@ -1388,6 +1389,12 @@ static zend_result php_session_send_cookie(void)
13881389 return FAILURE ;
13891390 }
13901391
1392+ /* Check for invalid settings combinations */
1393+ if (UNEXPECTED (PS (cookie_partitioned ) && !PS (cookie_secure ))) {
1394+ php_error_docref (NULL , E_WARNING , "Partitioned session cookie cannot be used without also configuring it as secure" );
1395+ return FAILURE ;
1396+ }
1397+
13911398 ZEND_ASSERT (strpbrk (ZSTR_VAL (PS (session_name )), SESSION_FORBIDDEN_CHARS ) == NULL );
13921399
13931400 /* URL encode id because it might be user supplied */
@@ -1432,6 +1439,10 @@ static zend_result php_session_send_cookie(void)
14321439 smart_str_appends (& ncookie , COOKIE_SECURE );
14331440 }
14341441
1442+ if (PS (cookie_partitioned )) {
1443+ smart_str_appends (& ncookie , COOKIE_PARTITIONED );
1444+ }
1445+
14351446 if (PS (cookie_httponly )) {
14361447 smart_str_appends (& ncookie , COOKIE_HTTPONLY );
14371448 }
@@ -1725,6 +1736,7 @@ PHP_FUNCTION(session_set_cookie_params)
17251736 zend_string * lifetime = NULL , * path = NULL , * domain = NULL , * samesite = NULL ;
17261737 bool secure = 0 , secure_null = 1 ;
17271738 bool httponly = 0 , httponly_null = 1 ;
1739+ bool partitioned = false, partitioned_null = true;
17281740 zend_string * ini_name ;
17291741 zend_result result ;
17301742 int found = 0 ;
@@ -1792,6 +1804,10 @@ PHP_FUNCTION(session_set_cookie_params)
17921804 secure = zval_is_true (value );
17931805 secure_null = 0 ;
17941806 found ++ ;
1807+ } else if (zend_string_equals_literal_ci (key , "partitioned" )) {
1808+ partitioned = zval_is_true (value );
1809+ partitioned_null = 0 ;
1810+ found ++ ;
17951811 } else if (zend_string_equals_literal_ci (key , "httponly" )) {
17961812 httponly = zval_is_true (value );
17971813 httponly_null = 0 ;
@@ -1856,6 +1872,15 @@ PHP_FUNCTION(session_set_cookie_params)
18561872 goto cleanup ;
18571873 }
18581874 }
1875+ if (!partitioned_null ) {
1876+ ini_name = ZSTR_INIT_LITERAL ("session.cookie_partitioned" , 0 );
1877+ result = zend_alter_ini_entry_chars (ini_name , partitioned ? "1" : "0" , 1 , PHP_INI_USER , PHP_INI_STAGE_RUNTIME );
1878+ zend_string_release_ex (ini_name , 0 );
1879+ if (result == FAILURE ) {
1880+ RETVAL_FALSE ;
1881+ goto cleanup ;
1882+ }
1883+ }
18591884 if (!httponly_null ) {
18601885 ini_name = ZSTR_INIT_LITERAL ("session.cookie_httponly" , 0 );
18611886 result = zend_alter_ini_entry_chars (ini_name , httponly ? "1" : "0" , 1 , PHP_INI_USER , PHP_INI_STAGE_RUNTIME );
@@ -1898,6 +1923,7 @@ PHP_FUNCTION(session_get_cookie_params)
18981923 add_assoc_str (return_value , "path" , zend_string_dup (PS (cookie_path ), false));
18991924 add_assoc_str (return_value , "domain" , zend_string_dup (PS (cookie_domain ), false));
19001925 add_assoc_bool (return_value , "secure" , PS (cookie_secure ));
1926+ add_assoc_bool (return_value , "partitioned" , PS (cookie_partitioned ));
19011927 add_assoc_bool (return_value , "httponly" , PS (cookie_httponly ));
19021928 add_assoc_str (return_value , "samesite" , zend_string_dup (PS (cookie_samesite ), false));
19031929}
0 commit comments