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