Skip to content

Fix GH-9932: Discards further characters for session name. #9940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ zend_class_entry *php_session_update_timestamp_iface_entry;
return FAILURE; \
}

#define SESSION_FORBIDDEN_CHARS "=,;.[ \t\r\n\013\014"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice! :)


#define APPLY_TRANS_SID (PS(use_trans_sid) && !PS(use_only_cookies))

static int php_session_send_cookie(void);
Expand Down Expand Up @@ -1254,7 +1256,7 @@ static void php_session_remove_cookie(void) {
size_t session_cookie_len;
size_t len = sizeof("Set-Cookie")-1;

ZEND_ASSERT(strpbrk(PS(session_name), "=,; \t\r\n\013\014") == NULL);
ZEND_ASSERT(strpbrk(PS(session_name), SESSION_FORBIDDEN_CHARS) == NULL);
spprintf(&session_cookie, 0, "Set-Cookie: %s=", PS(session_name));

session_cookie_len = strlen(session_cookie);
Expand Down Expand Up @@ -1302,8 +1304,8 @@ static zend_result php_session_send_cookie(void) /* {{{ */
}

/* Prevent broken Set-Cookie header, because the session_name might be user supplied */
if (strpbrk(PS(session_name), "=,; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */
php_error_docref(NULL, E_WARNING, "session.name cannot contain any of the following '=,; \\t\\r\\n\\013\\014'");
if (strpbrk(PS(session_name), SESSION_FORBIDDEN_CHARS) != NULL) { /* man isspace for \013 and \014 */
php_error_docref(NULL, E_WARNING, "session.name cannot contain any of the following '=,;.[ \\t\\r\\n\\013\\014'");
return FAILURE;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/session/tests/session_name_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool(true)
string(9) "PHPSESSID"
string(9) "PHPSESSID"

Warning: session_start(): session.name cannot contain any of the following '=,; \t\r\n\013\014' in %s on line %d
Warning: session_start(): session.name cannot contain any of the following '=,;.[ \t\r\n\013\014' in %s on line %d
bool(true)
string(1) " "
bool(true)
Expand All @@ -54,7 +54,7 @@ string(1) " "
Warning: session_name(): session.name "" cannot be numeric or empty in %s on line %d
string(1) " "

Warning: session_start(): session.name cannot contain any of the following '=,; \t\r\n\013\014' in %s on line %d
Warning: session_start(): session.name cannot contain any of the following '=,;.[ \t\r\n\013\014' in %s on line %d
bool(true)
string(1) " "
bool(true)
Expand Down