@@ -1264,13 +1264,11 @@ static void php_session_remove_cookie(void) {
1264
1264
zend_llist_element * next ;
1265
1265
zend_llist_element * current ;
1266
1266
char * session_cookie ;
1267
- zend_string * e_session_name ;
1268
1267
size_t session_cookie_len ;
1269
1268
size_t len = sizeof ("Set-Cookie" )- 1 ;
1270
1269
1271
- e_session_name = php_url_encode (PS (session_name ), strlen (PS (session_name )));
1272
- spprintf (& session_cookie , 0 , "Set-Cookie: %s=" , ZSTR_VAL (e_session_name ));
1273
- zend_string_free (e_session_name );
1270
+ ZEND_ASSERT (strpbrk (PS (session_name ), "=,; \t\r\n\013\014" ) == NULL );
1271
+ spprintf (& session_cookie , 0 , "Set-Cookie: %s=" , PS (session_name ));
1274
1272
1275
1273
session_cookie_len = strlen (session_cookie );
1276
1274
current = l -> head ;
@@ -1302,7 +1300,7 @@ static int php_session_send_cookie(void) /* {{{ */
1302
1300
{
1303
1301
smart_str ncookie = {0 };
1304
1302
zend_string * date_fmt = NULL ;
1305
- zend_string * e_session_name , * e_id ;
1303
+ zend_string * e_id ;
1306
1304
1307
1305
if (SG (headers_sent )) {
1308
1306
const char * output_start_filename = php_output_get_start_filename ();
@@ -1316,16 +1314,20 @@ static int php_session_send_cookie(void) /* {{{ */
1316
1314
return FAILURE ;
1317
1315
}
1318
1316
1319
- /* URL encode session_name and id because they might be user supplied */
1320
- e_session_name = php_url_encode (PS (session_name ), strlen (PS (session_name )));
1317
+ /* Prevent broken Set-Cookie header, because the session_name might be user supplied */
1318
+ if (strpbrk (PS (session_name ), "=,; \t\r\n\013\014" ) != NULL ) { /* man isspace for \013 and \014 */
1319
+ php_error_docref (NULL , E_WARNING , "session.name cannot contain any of the following '=,; \\t\\r\\n\\013\\014'" );
1320
+ return FAILURE ;
1321
+ }
1322
+
1323
+ /* URL encode id because it might be user supplied */
1321
1324
e_id = php_url_encode (ZSTR_VAL (PS (id )), ZSTR_LEN (PS (id )));
1322
1325
1323
1326
smart_str_appendl (& ncookie , "Set-Cookie: " , sizeof ("Set-Cookie: " )- 1 );
1324
- smart_str_appendl (& ncookie , ZSTR_VAL ( e_session_name ), ZSTR_LEN ( e_session_name ));
1327
+ smart_str_appendl (& ncookie , PS ( session_name ), strlen ( PS ( session_name ) ));
1325
1328
smart_str_appendc (& ncookie , '=' );
1326
1329
smart_str_appendl (& ncookie , ZSTR_VAL (e_id ), ZSTR_LEN (e_id ));
1327
1330
1328
- zend_string_release_ex (e_session_name , 0 );
1329
1331
zend_string_release_ex (e_id , 0 );
1330
1332
1331
1333
if (PS (cookie_lifetime ) > 0 ) {
0 commit comments