Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[HttpFoundation][HttpKernel] Configuresession.cookie_secure earlier#40231
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedFeb 18, 2021
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
jderusse left a comment
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.
I think this PR works in your case because your php.ini file hascookie_secure=on and this PR prevent overriding the .ini value with"auto".
But what if your .ini is set toon and you call the page withhttp does it removes thecookie_secure flag? Or what if the .ini is set tooff and the page is called withhttps is it re-added?
I believe we should disable the .ini setting when value isauto then the SessionListener will re-enabled it if the request is secured.
Are you sure that your Code/EventListener has a lower priority than theSessionListener and you are not reading the session before the flag is correctly sets?
Note: In Symfony 5.3, injecting the session in your service will be deprecated and you'll have to use the RequestStack to get a session. So this will not be an issue anymore, as you won't be able to manipulate the session before the SessionListener initialize the storage and inject the session in the request.
Uh oh!
There was an error while loading.Please reload this page.
tamcy commentedFeb 18, 2021
But 'auto' is not a valid value for this ini setting. Yes, setting
You are correct that this PR missed the scenario when the page is accessed through http, not https. The code only sets cookie_secure to if ($this->container->has('session_storage') && ($storage =$this->container->get('session_storage'))instanceof NativeSessionStorage && ($masterRequest =$this->container->get('request_stack')->getMasterRequest()) ) {$storage->setOptions(['cookie_secure' =>$masterRequest->isSecure()]); }
Personally I don't have preference on whether the setting is set in one place, or is first disabled then enabled if the traffic in https. But again, I think the value passed to ini_set shouldn't be 'auto'.
I need to confess that my experience with Symfony internals isn't deep enough for me to guarantee that people will be immune from similar situations. They may still able to register an event listener which accesses the session before SessionListener is called, causing it to fail to properly set the |
stof commentedFeb 18, 2021
no it is not. And that's precisely why this PR will fix the issue by making sure that the |
0016095 to519eb1cComparetamcy commentedFeb 19, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@stof is right. I forgot to update my mind when writing the reply. The PR has been updated. In this PR,
Two related notes:
|
session.cookie_secure earlier519eb1c toe82918cCompare
nicolas-grekas left a comment
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.
(implem updated a bit)
session.cookie_secure earliersession.cookie_secure earliernicolas-grekas commentedFeb 25, 2021
Thank you@tamcy. |
stof commentedFeb 25, 2021
this is fine to me. On future versions where accessing the session as a service is not possible anymore, you won't be able to access the session before it is initialized in the Request by SessionListener (which is also why it runs at priority 100) |
tamcy commentedFeb 28, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@nicolas-grekas Thank you. May I know if it is intentional to use my first pull request, rather than the second one? I ask this because besides the difference in approach, the second PR includes a fix in the if ($this->container->has('session_storage') && ($storage =$this->container->get('session_storage'))instanceof NativeSessionStorage && ($masterRequest =$this->container->get('request_stack')->getMasterRequest()) &&$masterRequest->isSecure() ) {$storage->setOptions(['cookie_secure' =>true]); } In this code, if the request is not https, the storage option will not be set. Consequently, the default PHP value will be used. If the default ini value is set to On (forcing secure cookie), the cookie will not work in an auto environment. Which is why the the code in the second PR, the code is changed to: if ($this->container->has('session_storage') && ($storage =$this->container->get('session_storage'))instanceof NativeSessionStorage && ($masterRequest =$this->container->get('request_stack')->getMasterRequest()) ) {$storage->setOptions(['cookie_secure' =>$masterRequest->isSecure()]); } Please advise what could be done. Shall I create another PR for this? Thank you! |
nicolas-grekas commentedFeb 28, 2021
Yes, I reverted that part because I thought it was not desired: the goal here is to upgrade to ssl when possible. Never to downgrade to no-ssl, which is what the change you're mentioning would do to me. |
tamcy commentedFeb 28, 2021
I see, thank you, this makes sense. Do we need a warning to users though? As this kind of downgrade does happen before the patch (the value is always set to "auto" at first, which effectively turns off the secure cookie flag). |
This PR does what@stof had suggested in#40221, allow me to quote him directly: