Vulnerability due to insecure default values for session.cookie_secure and session.cookie_httponly
Description
Dear colleagues,
it seems that the default values for the SECURE and HTTPONLY flags of cookies, especially for the PHP session cookie, (PHPSESSID) are not set to true. This opens a hidden vulnerability for serious XSS attacks.
Developers which use setcookie() and explicitly define $secure and $httponly might not be aware (they have done their work and feel safe), that they additionally have to explicitly set these values in session_set_cookie_params() to protect the PHPSESSID cookie from being stolen due to trivial XSS attacks:
session_set_cookie_params(['secure' => true, 'httponly' => true]);
I kindly ask you to confirm this issue and move to secure-per-default for this.
Kind Regards, etkaar
PHP Version
PHP 7-8
Operating System
No response
See also: #13720 (successful XSS reported)
I put the autostart disabling into .htaccess and ran my test. The result was PHPSESSID cookie has HttpOnly: false, Secure: false.
Make sure changes in .htaccess are actually effective on your server, use print_r(ini_get_all('session', false));.
I've tested session_set_cookie_params on my server and it's working perfectly fine even on PHP 7.4. session_set_cookie_params in fact changes ini settings: https://3v4l.org/cWO3Z Problem is somewhere on your end, and this is not good place for troubleshooting - issue went off topic.
cookie_secure is true, auto-start is false.
Make sure to remove existing PHPSESSID, then after session_start you can verify what php is setting in set-cookie header: print_r(headers_list());.
and this is not good place for troubleshooting - issue went off topic.
That. See https://www.php.net/support about available support channels; and of course, there is also StackOverflow etc.
This has slacked a bit, but in my opinion setting the HTTPONLY and Secure flags should indeed be default behaviour. At the moment defaulting to a insecure setting has no good reason, and I often find web applications that leave this behaviour at the default setting without understanding that this could help to address potential serious risks.
This might require RFC, but please contact mailing list first https://wiki.php.net/rfc/howto
I did the first step, will wait for reaction
I did the first step, will wait for reaction
Thanks!
Just as the Let's Encrypt initiative resulted in better security for the Web, so would setting these two cookie options by default, clearing them only for special purposes (maybe HTTPONLY for using JavaScript for testing, or SECURE for IoT applications that must run on insecure http connections).
@joostgrunwald Did you ever send out that e-mail? I cannot find it.
Hi, my website just got exploited by XSS and the attacker had access to the session cookies because of the unsafe session cookie defaults. I'm really sad that this conversation died between off-topic comments, so I wrote down all my thoughts in a PR: https://github.com/php/php-src/pull/13720
And I reported this vulnerability already years ago to the PHP team ☹️
PHP is language but PHP has built in server module. so PHP's default settings should be changed to safe settings.
I think a good language should be default setting simple and secure.
@cmb69 Hi! Any way to push this issue a little bit forward? At least for PHP 9 it should be no problem to change the default to secure, as insecurely configured cookies as default can be considered as unexpected behaviour.
I'm unable to send emails to the PHP email lists, I'm giving up on PHP
edit: https://github.com/php/php-src/pull/13720#issuecomment-2348487514
Apparently, that issue fell through the cracks. Sorry, but this can happen given the huge amount of tickets.
Anyhow, I think that changing the defaults should be done as soon as possible (unfortunately a bit late for PHP 8.4, probably), and it makes sense to consider to even deprecate changing the new defaults (like it was done for a couple of other session settings in PHP 8.4).
But this should better be discussed on the internals mailing list. This is the official discussion medium for php-src. Discussions on GH are better restricted to details, and wrt PRs, to technical/implementation issues. @etkaar, did you already try to contact the internals mailing list?
(See blow, my fault)
@cmb69 I sent this email, but no success:
Hi!
I've created this issue in January 2022 but it seems it wasn't noticed yet (since you probably do watch the mailing lists more than GitHub):
https://github.com/php/php-src/issues/7913
Kind Regards,
etkaar
Neither can I subscribe using the form on https://www.php.net/mailing-lists.php (always tells me the email address is invalid), nor can I subscribe sending an email with subject subscribe to [email protected], I simply don't receive a response, I tried it multiple times and also checked my mailserver.
I even tried it using telnet, but still no response:
@etkaar, I believe your email address is invalid. You need to trim the angle-brackets (e.g. use [email protected] instead of <[email protected]>).
(See blow, my fault)
@cmb69 That unfortunately makes no difference, I tried it also without brackets (= addr-spec).
I've written to systems@ so they can have a look at this.