|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-08-21 13:49 UTC] cmanley at xs4all dot nl
Description:
------------
PHP doesn't validate the session id cookie name. Hackers can manipulate it's value
and try to overwrite non-session files in sites where custom file based session
handlers are used.
I use database based handlers, so it doesn't apply to me, but I was surprised to
see that PHP let the cookie in that I manipulated.
Test script:
---------------
This is debugging from my session handler showing the methods called and arguments with my illegal cookie value '../../../../../../../../var/www/site.com/htdocs/index.php'
SessionManagerPDO::_open('/var/lib/php5', 'PHPSESSID')
SessionManagerPDO::_read('../../../../../../../../var/www/site.com/htdocs/index.php')
(returns empty string because it finds no row)
SessionManagerPDO::_write('../../../../../../../../var/www/site.com/htdocs/index.php', [0 bytes, md5=d41d8cd98f00b204e9800998ecf8427e])
(attempts to insert new row into database, but dies because session_id field is too wide)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 05:00:01 2025 UTC |
It is the job of the handler to validate session IDs. the default file handler uses this whitelist: for (p = key; (c = *p); p++) { /* valid characters are a..z,A..Z,0..9 */ if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == ',' || c == '-')) { ret = FAILURE; break; } } See http://lxr.php.net/xref/PHP_TRUNK/ext/session/session.c#php_session_valid_key