-
Notifications
You must be signed in to change notification settings - Fork 8.1k
ext/session: reject cookie separators in cookie_path and cookie_domain #22925
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --TEST-- | ||
| session.cookie_path and session.cookie_domain reject cookie separators | ||
| --INI-- | ||
| session.save_handler=files | ||
| session.name=PHPSESSID | ||
| session.gc_probability=0 | ||
| --EXTENSIONS-- | ||
| session | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| ob_start(); | ||
|
|
||
| var_dump(session_set_cookie_params(['path' => '/; Domain=evil.example'])); | ||
| var_dump(session_set_cookie_params(['domain' => 'example.com; HttpOnly'])); | ||
| var_dump(session_set_cookie_params(['path' => "/\r\nX-Injected: yes"])); | ||
| var_dump(ini_set('session.cookie_domain', "example.com\tevil")); | ||
|
|
||
| $params = session_get_cookie_params(); | ||
| var_dump($params['path'], $params['domain']); | ||
|
|
||
| var_dump(session_set_cookie_params(['path' => '/app', 'domain' => 'example.com'])); | ||
| $params = session_get_cookie_params(); | ||
| var_dump($params['path'], $params['domain']); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Warning: session_set_cookie_params(): "session.cookie_path" must not contain any of the following characters ",; \t\r\n\013\014" in %s on line %d | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of these characters seem as they may be legitimately used in paths. It could be possible to have a path with a space or a comma in it. Perhaps https://datatracker.ietf.org/doc/html/rfc6265 can be used to more precisely determine which characters can be in which field.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RFC 6265 Path allows space and comma; Domain does not. Browsers split cookie-av on This copies setcookie()'s path/domain check. Loosening session.cookie_path alone would accept values setcookie() still rejects.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Making this consistent with setcookie makes sense. Even so, there is a slight risk of BC break when someone configured
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
setcookie() has rejected both in path since 7.3. I'd rather keep that set than special-case session.cookie_path.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I was wrong about this. Having a space in the cookie path doesn't work. It seems that the browser automatically encodes the space in the path to %20, so the cookie path should also have %20 for it to match. A comma works though. I consider it less likely that people use a comma in their path, but having @cmb69 do you have any thoughts on this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that @cmb69 copied the validation from cookie value to cookie path. This is not entirely correct, since these can contain different characters according to the RFC. I don't think it is a good idea to persist the mistake into the INI values. I can see the following ways forward:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a copy-paste error. 5cb825d's message is explicit: "characters not allowed for name and value should also be forbidden for path and domain." Comma in a path is RFC-legal, but RFC 6265 section 3 bans folding Set-Cookie precisely because "," conflicts with standard header folding, so anything that folds or re-splits on commas misreads a comma'd path. I'd keep setcookie's set here; relaxing both to the RFC grammar is a setcookie() question, and this INI handler would follow it. |
||
| bool(false) | ||
|
|
||
| Warning: session_set_cookie_params(): "session.cookie_domain" must not contain any of the following characters ",; \t\r\n\013\014" in %s on line %d | ||
| bool(false) | ||
|
|
||
| Warning: session_set_cookie_params(): "session.cookie_path" must not contain any of the following characters ",; \t\r\n\013\014" in %s on line %d | ||
| bool(false) | ||
|
|
||
| Warning: ini_set(): "session.cookie_domain" must not contain any of the following characters ",; \t\r\n\013\014" in %s on line %d | ||
| bool(false) | ||
| string(1) "/" | ||
| string(0) "" | ||
| bool(true) | ||
| string(4) "/app" | ||
| string(11) "example.com" | ||
Uh oh!
There was an error while loading. Please reload this page.