@@ -79,7 +79,7 @@ PHPAPI int php_header(void)
79
79
#define ILLEGAL_COOKIE_CHARACTER "\",\", \";\", \" \", \"\\t\", \"\\r\", \"\\n\", \"\\013\", or \"\\014\""
80
80
PHPAPI zend_result php_setcookie (zend_string * name , zend_string * value , time_t expires ,
81
81
zend_string * path , zend_string * domain , bool secure , bool httponly ,
82
- zend_string * samesite , bool url_encode )
82
+ zend_string * samesite , bool partitioned , bool url_encode )
83
83
{
84
84
zend_string * dt ;
85
85
sapi_header_line ctr = {0 };
@@ -117,6 +117,11 @@ PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t e
117
117
return FAILURE ;
118
118
}
119
119
#endif
120
+ if (partitioned && !secure ) {
121
+ zend_value_error ("%s(): \"partitioned\" option cannot be used without \"secure\" option" ,
122
+ get_active_function_name ());
123
+ return FAILURE ;
124
+ }
120
125
121
126
/* Should check value of SameSite? */
122
127
@@ -182,6 +187,9 @@ PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t e
182
187
smart_str_appends (& buf , COOKIE_SAMESITE );
183
188
smart_str_append (& buf , samesite );
184
189
}
190
+ if (partitioned ) {
191
+ smart_str_appends (& buf , COOKIE_PARTITIONED );
192
+ }
185
193
186
194
ctr .line = ZSTR_VAL (buf .s );
187
195
ctr .line_len = (uint32_t ) ZSTR_LEN (buf .s );
@@ -192,7 +200,7 @@ PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t e
192
200
}
193
201
194
202
static zend_result php_head_parse_cookie_options_array (HashTable * options , zend_long * expires , zend_string * * path ,
195
- zend_string * * domain , bool * secure , bool * httponly , zend_string * * samesite )
203
+ zend_string * * domain , bool * secure , bool * httponly , zend_string * * samesite , bool * partitioned )
196
204
{
197
205
zend_string * key ;
198
206
zval * value ;
@@ -214,6 +222,8 @@ static zend_result php_head_parse_cookie_options_array(HashTable *options, zend_
214
222
* httponly = zval_is_true (value );
215
223
} else if (zend_string_equals_literal_ci (key , "samesite" )) {
216
224
* samesite = zval_get_string (value );
225
+ } else if (zend_string_equals_literal_ci (key , "partitioned" )) {
226
+ * partitioned = zval_is_true (value );
217
227
} else {
218
228
zend_value_error ("%s(): option \"%s\" is invalid" , get_active_function_name (), ZSTR_VAL (key ));
219
229
return FAILURE ;
@@ -227,7 +237,7 @@ static void php_setcookie_common(INTERNAL_FUNCTION_PARAMETERS, bool is_raw)
227
237
HashTable * options = NULL ;
228
238
zend_long expires = 0 ;
229
239
zend_string * name , * value = NULL , * path = NULL , * domain = NULL , * samesite = NULL ;
230
- bool secure = 0 , httponly = 0 ;
240
+ bool secure = 0 , httponly = 0 , partitioned = false ;
231
241
232
242
ZEND_PARSE_PARAMETERS_START (1 , 7 )
233
243
Z_PARAM_STR (name )
@@ -248,13 +258,13 @@ static void php_setcookie_common(INTERNAL_FUNCTION_PARAMETERS, bool is_raw)
248
258
}
249
259
250
260
if (FAILURE == php_head_parse_cookie_options_array (options , & expires , & path ,
251
- & domain , & secure , & httponly , & samesite )
261
+ & domain , & secure , & httponly , & samesite , & partitioned )
252
262
) {
253
263
goto cleanup ;
254
264
}
255
265
}
256
266
257
- if (php_setcookie (name , value , expires , path , domain , secure , httponly , samesite , !is_raw ) == SUCCESS ) {
267
+ if (php_setcookie (name , value , expires , path , domain , secure , httponly , samesite , partitioned , !is_raw ) == SUCCESS ) {
258
268
RETVAL_TRUE ;
259
269
} else {
260
270
RETVAL_FALSE ;
0 commit comments