Skip to content

Commit a4298c1

Browse files
committed
Fix GH-9932: Discards further characters for session name.
As those are converted, it s better to make aware of the code caller of the naming inadequacy. Closes GH-9940.
1 parent a8bd342 commit a4298c1

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ PHP NEWS
1616
. Fixed bug GH-9298 (Signal handler called after rshutdown leads to crash).
1717
(Erki Aring)
1818

19+
- Session:
20+
. Fixed GH-9932 (session name silently fails with . and [). (David Carlier)
21+
1922
24 Nov 2022, PHP 8.1.13
2023

2124
- CLI:

ext/session/session.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ zend_class_entry *php_session_update_timestamp_iface_entry;
9494
return FAILURE; \
9595
}
9696

97+
#define SESSION_FORBIDDEN_CHARS "=,;.[ \t\r\n\013\014"
98+
9799
#define APPLY_TRANS_SID (PS(use_trans_sid) && !PS(use_only_cookies))
98100

99101
static int php_session_send_cookie(void);
@@ -1268,7 +1270,7 @@ static void php_session_remove_cookie(void) {
12681270
size_t session_cookie_len;
12691271
size_t len = sizeof("Set-Cookie")-1;
12701272

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

12741276
session_cookie_len = strlen(session_cookie);
@@ -1316,8 +1318,8 @@ static int php_session_send_cookie(void) /* {{{ */
13161318
}
13171319

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

ext/session/tests/session_name_variation1.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool(true)
4545
string(9) "PHPSESSID"
4646
string(9) "PHPSESSID"
4747

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

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

0 commit comments

Comments
 (0)