Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:5.4fromsimonchrz:fix-44550-phpsessionoptions
Dec 20, 2021

Conversation

@simonchrz
Copy link
Contributor

QA
Branch?5.4
Bug fix?yes
TicketsFix#44500
LicenseMIT

Fixes issue on SessionListener, not taken session.cookie_* settings into account anymore.

fritzmg, bytehead, GregOriol, Coderberg, alexander-schranz, n3o77, ErnadoO, and mbtreetime reacted with thumbs up emojialexander-schranz reacted with rocket emoji
@simonchrz
Copy link
ContributorAuthor

@alexander-schranz maybe you could review this please ?

@carsonbotcarsonbot changed the titletake php session.cookie settings into account...[HttpFoundation] take php session.cookie settings into account...Dec 9, 2021
@alexander-schranz
Copy link
Contributor

@simonchrz sorry for the noice. Overall I think we should need to duplicate here some thing from theNativeSessionStorage to solve this problem correctly.

I would go with the following in the__construct method so we are sure the value inside$this->sessionOptions is always the correct one:

$this->sessionOptions = [];foreach (session_get_cookie_params()as$key =>$value) {$this->sessionOptions['cookie_' .$key] =>$value;}foreach ($sessionOptionsas$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-L394if (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 inhttps://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.

@derrabus
Copy link
Member

@simonchrz Are you able to write a test for your change? I really want to make sure, we don't break this behavior again.

@chalasrchalasr changed the title[HttpFoundation] take php session.cookie settings into account...[HttpFoundation] Take php session.cookie settings into accountDec 13, 2021
@simonchrz
Copy link
ContributorAuthor

@alexander-schranz i've followed your suggestion, please double check. 👍
@derrabus added a test, too.

@alexander-schranz
Copy link
Contributor

alexander-schranz commentedDec 14, 2021
edited
Loading

@simonchrz as I see there is also issue aboutcookie_secure: auto not correctly working. And this PR also seems to fix this. Can you add an additional test case wherecookie_secure: auto is set by symfony and php has it set to false/off, before it seems to be always true in auto mode.

@X-Coder264
Copy link
Contributor

X-Coder264 commentedDec 15, 2021
edited
Loading

@simonchrz@alexander-schranz I don't think this completely fixes the problem with theauto setting. ThemergePhpSessionOptions thing gets called too early for that.

In a normal Symfony request lifecycle the session listener is one of the first things that gets called on thekernel.request event which means it's one of the first listeners that gets constructed. TheonKernelRequest method sets the session factory callback which gets triggered the first time somebody tries to access the session. That callback will then eventually call\Symfony\Component\HttpFoundation\Session\Storage\SessionStorageFactoryInterface::createStorage whose implementations then setcookie_secure option totrue if the framework configuration value wasauto ortrue and the request is secure ->https://github.com/symfony/symfony/blob/v5.4.1/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorageFactory.php#L44

Since themergePhpSessionOptions method was already called in the constructor it did not take into consideration the PHP ini settings change that the session storage factory (potentially) made so by the time$sessionCookieSecure = $this->sessionOptions['cookie_secure'] ?? false; executes on thekernel.response event$this->sessionOptions['cookie_secure'] will befalse instead oftrue (in the case when the request was secure, when PHP has it set tofalse andauto was specified in the framework configuration).

The fix for this would probably be to not callmergePhpSessionOptions in the constructor and instead of accessing$this->sessionOptions directly in theonKernelResponse a getter can be called which would trigger themergePhpSessionOptions logic. That way we ensure that that logic is called at the last possible moment and with that we ensure thatsession_get_cookie_params() returns the correct/expected values (as those values can be changed between the constructor and thekernel.response event handling, as described above).

chalasr, alexander-schranz, and simonchrz reacted with thumbs up emoji

@alexander-schranz
Copy link
Contributor

@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 ofmergePhpSessionOptions from__construct where$this->sessionOptions is currently use by doing:

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

X-Coder264 and simonchrz reacted with thumbs up emoji

Copy link
Contributor

@alexander-schranzalexander-schranz left a 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_secureauto with native secure disabled should be added, or did I miss that one?

@simonchrz
Copy link
ContributorAuthor

Changes looks good. Thank you 👍 . Still a test for symfony using cookie_secureauto 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 ? :-)

@alexander-schranz
Copy link
Contributor

@simonchrz Thx, no problem. Will try to have a look at the evening at it.

@Jelle-S
Copy link

I can confirm this fixes#44541

simonchrz reacted with thumbs up emoji

@alexander-schranz
Copy link
Contributor

@simonchrz This two additonal test cases cover thecookie_secureauto behaviour:

'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],            ],

@simonchrz
Copy link
ContributorAuthor

@alexander-schranz thanks for the hint == i've just added them to the provider

alexander-schranz reacted with thumbs up emoji

@simonchrz
Copy link
ContributorAuthor

Why isn't 5.3 affected?

issue comes from refactoring on#41390 which isn't backmerged to 5.3 for some reason...

nicolas-grekas and mbtreetime reacted with thumbs up emoji

@simonchrz
Copy link
ContributorAuthor

I am on version 5.4.1 and I guess. that I am affected by the Invalid CSRF problems, I have had to put in all my options csrf_ * => false to force the operation, any idea when I can update simfony with composer to return to normality?

i guess with 5.4.2 ? ;)

@sxsws
Copy link

I think the real question is why wasn't this problem caught on such a mature project?

@nicolas-grekas
Copy link
Member

🤷

wouterj and dmaicher reacted with thumbs up emoji

@simonchrz
Copy link
ContributorAuthor

@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

@simonchrzsimonchrzforce-pushed thefix-44550-phpsessionoptions branch from32c8e36 to3257a3bCompareDecember 18, 2021 13:55
@derrabus
Copy link
Member

any idea how to fix thos 8.0, macos-11 test of messenger component ?

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.

simonchrz reacted with thumbs up emoji

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

(after minor change)

@fabpotfabpotforce-pushed thefix-44550-phpsessionoptions branch from8d6405e to23bd7a7CompareDecember 20, 2021 09:29
@fabpot
Copy link
Member

Thank you@simonchrz.

simonchrz and wnunezc reacted with heart emoji

@fabpotfabpot merged commitccd8014 intosymfony:5.4Dec 20, 2021
@alexander-schranz
Copy link
Contributor

alexander-schranz commentedDec 20, 2021
edited
Loading

@simonchrz Thank you for fixing this, great work 👍

RonnieRocket147, wnunezc, n3o77, GregOriol, sxsws, and zkimi reacted with thumbs up emojisimonchrz, derrabus, and GregOriol reacted with rocket emoji

@wnunezc
Copy link

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

derrabus added a commit that referenced this pull requestDec 21, 2021
…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/AThe 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
This was referencedDec 29, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@derrabusderrabusderrabus approved these changes

+2 more reviewers

@stloydstloydstloyd left review comments

@alexander-schranzalexander-schranzalexander-schranz approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

12 participants

@simonchrz@alexander-schranz@derrabus@X-Coder264@Jelle-S@nicolas-grekas@wnunezc@sxsws@fabpot@stloyd@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp