-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Take php session.cookie settings into account #44518
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
Conversation
@alexander-schranz maybe you could review this please ? |
@simonchrz sorry for the noice. Overall I think we should need to duplicate here some thing from the I would go with the following in the $this->sessionOptions = [];
foreach (session_get_cookie_params() as $key => $value) {
$this->sessionOptions['cookie_' . $key] => $value;
}
foreach ($sessionOptions as $key => $value) {
// do the same logic as in the NativeSessionStorage
// @see https://github.com/symfony/symfony/blob/v5.4.0/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php#L392-L394
if (isset($validOptions[$key])) {
if ('cookie_secure' === $key && 'auto' === $value) {
continue;
}
$this->sessionOptions[$key] = $value;
}
} We need to check if symfony is forcing some specific values in https://github.com/symfony/symfony/blob/v5.4.0/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php specially if samesite work correctly still for lower PHP Versions. |
@simonchrz Are you able to write a test for your change? I really want to make sure, we don't break this behavior again. |
@alexander-schranz i've followed your suggestion, please double check. 👍 |
src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php
Show resolved
Hide resolved
src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php
Show resolved
Hide resolved
@simonchrz as I see there is also issue about |
@simonchrz @alexander-schranz I don't think this completely fixes the problem with the In a normal Symfony request lifecycle the session listener is one of the first things that gets called on the Since the The fix for this would probably be to not call |
@X-Coder264 Thank you for the detailed response and testing this out. Was not aware of it that it was currently possible to change the Storage Options from outside. Then it definitly make sense that we move the call of $sessionOptions = $this->getMergedPhpSessionOptions();
$sessionCookiePath = $sessionOptions['cookie_path'] ?? '/';
// ... Would be interesting how we could create a functional test case for this. To avoid this errors in the future. @simonchrz sorry for the circumstances. And really thank you for working on this. |
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.
Changes looks good. Thank you 👍 . Still a test for symfony using cookie_secure auto
with native secure disabled should be added, or did I miss that one?
nope, i'm actually struggling with adding this one... maybe you could jump in writing this test ? :-) |
@simonchrz Thx, no problem. Will try to have a look at the evening at it. |
I can confirm this fixes #44541 |
@simonchrz This two additonal test cases cover the 'set_cookiesecure_auto_by_symfony_false_by_php' => [
'phpSessionOptions' => ['secure' => false],
'sessionOptions' => ['cookie_path' => '/test/', 'cookie_httponly' => 'auto', 'cookie_secure' => 'auto', 'cookie_samesite' => Cookie::SAMESITE_LAX],
'expectedSessionOptions' => ['cookie_path' => '/test/', 'cookie_domain' => '', 'cookie_secure' => false, 'cookie_httponly' => true, 'cookie_samesite' => Cookie::SAMESITE_LAX],
],
'set_cookiesecure_auto_by_symfony_true_by_php' => [
'phpSessionOptions' => ['secure' => true],
'sessionOptions' => ['cookie_path' => '/test/', 'cookie_httponly' => 'auto', 'cookie_secure' => 'auto', 'cookie_samesite' => Cookie::SAMESITE_LAX],
'expectedSessionOptions' => ['cookie_path' => '/test/', 'cookie_domain' => '', 'cookie_secure' => true, 'cookie_httponly' => true, 'cookie_samesite' => Cookie::SAMESITE_LAX],
], |
@alexander-schranz thanks for the hint == i've just added them to the provider |
issue comes from refactoring on #41390 which isn't backmerged to 5.3 for some reason... |
i guess with 5.4.2 ? ;) |
I think the real question is why wasn't this problem caught on such a mature project? |
🤷 |
@nicolas-grekas any idea how to fix thos 8.0, macos-11 test of messenger component ? they seem to have some kind of disk I/O issues ? https://github.com/symfony/symfony/runs/4569511187?check_suite_focus=true#step:9:2464 |
32c8e36
to
3257a3b
Compare
src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php
Outdated
Show resolved
Hide resolved
That test is not related to these changes, is it? You don't need to bother then. The macOS test suite is relatively new and we still have some flaky tests there. |
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.
(after minor change)
src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php
Outdated
Show resolved
Hide resolved
8d6405e
to
23bd7a7
Compare
Thank you @simonchrz. |
@simonchrz Thank you for fixing this, great work 👍 |
a great job let's wait for the 5.4.2 release to pull the XD, I think I'll have to revert some changes. |
…rabus) This PR was merged into the 5.4 branch. Discussion ---------- [HttpKernel] Don't rely on session service in tests | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Follow-up to #44518 | License | MIT | Doc PR | N/A The test introduced by #44518 makes use of the deprecated session service mechanism. Instead, I've attached the session to the request. This allows us to merge the test up to 6.0 and beyond without breaking it. Commits ------- e963594 Don't rely on session service in tests
Fixes issue on SessionListener, not taken session.cookie_* settings into account anymore.