php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Vulnerability due to insecure default values for session.cookie_secure and session.cookie_httponly

Open etkaar opened this issue 4 years ago • 49 comments

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)

etkaar avatar Jan 08 '22 16:01 etkaar

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.

KapitanOczywisty avatar Jul 19 '22 21:07 KapitanOczywisty

cookie_secure is true, auto-start is false.

David263 avatar Jul 19 '22 21:07 David263

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());.

KapitanOczywisty avatar Jul 19 '22 21:07 KapitanOczywisty

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.

cmb69 avatar Jul 19 '22 21:07 cmb69

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.

joostgrunwald avatar Jun 30 '23 09:06 joostgrunwald

This might require RFC, but please contact mailing list first https://wiki.php.net/rfc/howto

KapitanOczywisty avatar Jun 30 '23 09:06 KapitanOczywisty

I did the first step, will wait for reaction

joostgrunwald avatar Jun 30 '23 09:06 joostgrunwald

I did the first step, will wait for reaction

Thanks!

etkaar avatar Jun 30 '23 09:06 etkaar

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).

David263 avatar Jun 30 '23 12:06 David263

@joostgrunwald Did you ever send out that e-mail? I cannot find it.

iluuu1994 avatar Oct 25 '23 09:10 iluuu1994

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

DaWe35 avatar Mar 15 '24 08:03 DaWe35

And I reported this vulnerability already years ago to the PHP team ☹️

etkaar avatar Mar 15 '24 09:03 etkaar

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.

xperia-query avatar May 09 '24 07:05 xperia-query

@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.

etkaar avatar Sep 12 '24 21:09 etkaar

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

DaWe35 avatar Sep 13 '24 06:09 DaWe35

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?

cmb69 avatar Sep 13 '24 09:09 cmb69

(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:

image

etkaar avatar Sep 13 '24 11:09 etkaar

@etkaar, I believe your email address is invalid. You need to trim the angle-brackets (e.g. use [email protected] instead of <[email protected]>).

cmb69 avatar Sep 13 '24 11:09 cmb69

(See blow, my fault)

@cmb69 That unfortunately makes no difference, I tried it also without brackets (= addr-spec).

etkaar avatar Sep 13 '24 12:09 etkaar

I've written to systems@ so they can have a look at this.

cmb69 avatar Sep 13 '24 12:09 cmb69