@@ -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 )
@@ -1362,6 +1363,12 @@ static zend_result php_session_send_cookie(void)
13621363 return FAILURE ;
13631364 }
13641365
1366+ /* Check for invalid settings combinations */
1367+ if (UNEXPECTED (PS (cookie_partitioned ) && !PS (cookie_secure ))) {
1368+ php_error_docref (NULL , E_WARNING , "Partitioned session cookie cannot be used without also configuring it as secure" );
1369+ return FAILURE ;
1370+ }
1371+
13651372 ZEND_ASSERT (strpbrk (ZSTR_VAL (PS (session_name )), SESSION_FORBIDDEN_CHARS ) == NULL );
13661373
13671374 /* URL encode id because it might be user supplied */
@@ -1406,6 +1413,10 @@ static zend_result php_session_send_cookie(void)
14061413 smart_str_appends (& ncookie , COOKIE_SECURE );
14071414 }
14081415
1416+ if (PS (cookie_partitioned )) {
1417+ smart_str_appends (& ncookie , COOKIE_PARTITIONED );
1418+ }
1419+
14091420 if (PS (cookie_httponly )) {
14101421 smart_str_appends (& ncookie , COOKIE_HTTPONLY );
14111422 }
@@ -1699,6 +1710,7 @@ PHP_FUNCTION(session_set_cookie_params)
16991710 zend_string * lifetime = NULL , * path = NULL , * domain = NULL , * samesite = NULL ;
17001711 bool secure = 0 , secure_null = 1 ;
17011712 bool httponly = 0 , httponly_null = 1 ;
1713+ bool partitioned = false, partitioned_null = true;
17021714 zend_string * ini_name ;
17031715 zend_result result ;
17041716 int found = 0 ;
@@ -1766,6 +1778,10 @@ PHP_FUNCTION(session_set_cookie_params)
17661778 secure = zval_is_true (value );
17671779 secure_null = 0 ;
17681780 found ++ ;
1781+ } else if (zend_string_equals_literal_ci (key , "partitioned" )) {
1782+ partitioned = zval_is_true (value );
1783+ partitioned_null = 0 ;
1784+ found ++ ;
17691785 } else if (zend_string_equals_literal_ci (key , "httponly" )) {
17701786 httponly = zval_is_true (value );
17711787 httponly_null = 0 ;
@@ -1830,6 +1846,15 @@ PHP_FUNCTION(session_set_cookie_params)
18301846 goto cleanup ;
18311847 }
18321848 }
1849+ if (!partitioned_null ) {
1850+ ini_name = ZSTR_INIT_LITERAL ("session.cookie_partitioned" , 0 );
1851+ result = zend_alter_ini_entry_chars (ini_name , partitioned ? "1" : "0" , 1 , PHP_INI_USER , PHP_INI_STAGE_RUNTIME );
1852+ zend_string_release_ex (ini_name , 0 );
1853+ if (result == FAILURE ) {
1854+ RETVAL_FALSE ;
1855+ goto cleanup ;
1856+ }
1857+ }
18331858 if (!httponly_null ) {
18341859 ini_name = ZSTR_INIT_LITERAL ("session.cookie_httponly" , 0 );
18351860 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)
18721897 add_assoc_str (return_value , "path" , zend_string_dup (PS (cookie_path ), false));
18731898 add_assoc_str (return_value , "domain" , zend_string_dup (PS (cookie_domain ), false));
18741899 add_assoc_bool (return_value , "secure" , PS (cookie_secure ));
1900+ add_assoc_bool (return_value , "partitioned" , PS (cookie_partitioned ));
18751901 add_assoc_bool (return_value , "httponly" , PS (cookie_httponly ));
18761902 add_assoc_str (return_value , "samesite" , zend_string_dup (PS (cookie_samesite ), false));
18771903}
0 commit comments