Skip to content

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Mar 26, 2020

The comment on PS_VALIDATE_SID_FUNC(files) is very clear that the
function is supposed to return SUCCESS if the session already exists.
So to detect a collision, we have to check for SUCCESS, not
FAILURE.

The comment on `PS_VALIDATE_SID_FUNC(files)` is very clear that the
function is supposed to return `SUCCESS` if the session already exists.
So to detect a collision, we have to check for `SUCCESS`, not
`FAILURE`.
If the new SID is invalid, i.e. no such session exists yet, there is no
need to create a new SID.  On the other hand, if such session already
exists, we have to create a new SID to satisfy strict mode (actually,
we would have to repeat this until we find an invalid SID).
@cmb69
Copy link
Member Author

cmb69 commented Mar 30, 2020

In my opinion, we should merge this fix ASAP (ideally before the next RCs are tagged tomorrow). See also https://bugs.php.net/bug.php?id=77178#1542784582 for reasons why (function name in the following quote fixed by me):

PHP_FUNCTION(session_create_id) and PHP_FUNCTION(session_regenerate_id) are both ACTIVELY trying to create collisions, because they are comparing against FAILURE instead of SUCCESS.

Also, @remicollet, what do you think about merging this into PHP-7.2. From https://bugs.php.net/bug.php?id=77178#1542803132:

I don't mind fixing this as minor security fix.

@nikic
Copy link
Member

nikic commented Mar 30, 2020

There's one more call here:

} else if (PS(use_strict_mode) && PS(mod)->s_validate_sid &&

Does it also need to be flipped?

@cmb69
Copy link
Member Author

cmb69 commented Mar 30, 2020

No, that call is supposed to check for FAILURE (the session is started, and a SID is given, and this session does not yet exists, in strict mode, a new SID has to be created => prevent session fixation).

@cmb69
Copy link
Member Author

cmb69 commented Mar 31, 2020

Thanks! Applied as b510250.

@nicolas-grekas
Copy link
Contributor

Is this going to be applied to PHP 7.2?
I submitted a PR on Symfony to work around the issue in previous versions of PHP and I'd like to ensure the affected versions are correctly listed, see
https://github.com/symfony/symfony/pull/36490/files#diff-d29419a0d7043fce54a98005c26a82aaR74

nicolas-grekas added a commit to symfony/symfony that referenced this pull request Apr 18, 2020
…(nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpFoundation] workaround PHP bug in the session module

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Current tests fail after php/php-src#5305
Which itself is a patch for a bug in the session module.

This PR works around the issue in older versions of PHP and fixes the tests.

Commits
-------

0cbca19 [HttpFoundation] workaround PHP bug in the session module
@cmb69
Copy link
Member Author

cmb69 commented Apr 18, 2020

@nicolas-grekas, that may be something to consider for @remicollet and @sgolemon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants