-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fix invalid session regeneration on wrong session ID #167
base: master
Are you sure you want to change the base?
Conversation
@fredericgboutin-yapla could you try to add a test case to https://github.com/zf1s/zf1/blob/master/tests/Zend/Session/SessionTest.php covering the issue, please? |
I really hoped there would be some tests already covering my fix 😅 but yes sure. |
Nothing broke in existing tests with your change that's true, but a test should be added to cover the bug - which would fail without the fix and would pass after the fix. |
@@ -459,7 +459,7 @@ public static function start($options = false) | |||
} | |||
|
|||
// See http://www.php.net/manual/en/ref.session.php for explanation | |||
if (!self::$_unitTestEnabled && defined('SID')) { | |||
if (!self::$_unitTestEnabled && defined('SID') && SID !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this condition is adding to the difficulty to properly unit-test
there's already a test named Looking at it, I guess the problem is that it does not let PHP figure the Since I cannot call Now let's try to put all this together... |
Hum... I think I got a bit out of my way in my last comment. The current test is alright. The problem is really when,
So what do we do from here? Well... I guess we have to make the Now about the I now really doubt the original purpose of Zend when using the Long story short, we should most probably drop 😩 I'm growing tired I think. |
We are successfully using a workaround like this, $sessionId = $_COOKIE['PHPSESSID'] ?? false;
if ($sessionId) {
session_id($sessionId);
}
Zend_Session::start(...); So maybe we could modify public static function getId()
{
$id = session_id();
if ($id === '' && isset($_COOKIE[session_name()])) {
return $_COOKIE[session_name()];
}
return $id;
} And NOT forcing a re-generation when creating a new session with an invalid ID, // Force a regenerate after session is started
if (self::$_sessionStarted) {
self::$_regenerateIdState = -1;
} It seems to work really well. Now to test this. 🤔 We must NOT call |
Fix for #165
Zend have a logic in place to create a valid session ID from the orignal value, MD5-ing it. This logic doesn't properly kick in the aforementioned situation of the issue but with this fix it does.
The fix does NOT prevent an initial write through the Session handler. This means that session with invalid keys are created into the database, file or redis instance in use for session storage.
In order to fix that, I'm afraid we would need to refactor the code to always md5 invalid entries pro-actively and since
getId()
is empty at that moment, I'm really not sure how we should to that.Note that the comment
// Check to see if we've been passed an invalid session ID
at the beginning of thestart()
method only really apply on an already opened session.