Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Flag all cookies as Secure #26731

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

Closed
DavidGarciaCat opened this issue Apr 1, 2018 · 6 comments
Closed

Flag all cookies as Secure #26731

DavidGarciaCat opened this issue Apr 1, 2018 · 6 comments

Comments

@DavidGarciaCat
Copy link

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? n/a
Symfony version n/a

As per @xabbuh 's suggestion on this other issue #26667 (comment) I believe that it's a problem when I set the flag for Secure Session Cookies but it doesn't affect the rest of the cookies that I have.

I believe that two global parameters to flag all Cookies as Secure as well as HttpOnly automatically (not just the Session Cookie) could provide a great enhancement to the framework, due it might help developers to increase the security of their projects on an easier way than the current case, where I need to add a new Kernel.ResponseListener to check for all existing cookies and re-set all of them with Secure flag in the event that they aren't.

Although I could use an update like this on several projects starting from Symfony 2.8 and ending on Symfony 4.x, I don't know if this is something that could be implemented on all these Symfony versions.

Happy to discuss!

@curry684
Copy link
Contributor

curry684 commented Apr 1, 2018

It's a new feature so it should go in master. However I do think it should also deprecate the session cookie setting as I'm not sure there would be a reason to just flag the session cookie and not others, unless you are on multiple domains, which should be configurable anyway in this feature.

@nicolas-grekas
Copy link
Member

I don't think we should change the default globally, as that would break portability (like "ini settings")
Thus I'd be 👎 here.

But for the session, see #28244 and #28338

@DavidGarciaCat
Copy link
Author

Hi @nicolas-grekas

For log in session, this was not a problem, as it was discussed with @xabbuh

If you believe this could break previous settings when moving to newer versions, then I would suggest thinking about this with another parameter, as I was suggesting. My point is that seems useless to ask me if I want to secure my Session Cookie but any other cookie is set by default with no security.

Maybe this can be included on next major release but seems useless to create an Event Listener to check all cookies on kernel.response to change this flag, instead Symfony could do this automatically based on an existing parameter, like:

null or false => do nothing (keep same behaviour)
true => secure the cookie automatically

Do you think this might be a problem?

@nicolas-grekas
Copy link
Member

I do, because that would make the setting global. I.e. bundles wouldn't be able to know what is the default. That's the exact same issue as with PHP ini settings.

@nicolas-grekas
Copy link
Member

See #28447

@DavidGarciaCat
Copy link
Author

Thanks, @nicolas-grekas - I'll follow the progress of that PR with high expectations!

@fabpot fabpot closed this as completed Sep 26, 2018
fabpot added a commit that referenced this issue Sep 26, 2018
… them $secure=null + plan to make it and samesite=lax the defaults in 5.0 (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[HttpFoundation] make cookies auto-secure when passing them $secure=null + plan to make it and samesite=lax the defaults in 5.0

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #26731
| License       | MIT
| Doc PR        | -

By creating Cookie instances using `null` for the `$secure` argument, this PR allows making cookies inherit their "secure" attribute from the request.

This PR also adds a forward to make $secure=null and samesite=lax the defaults in Symfony 5.0:
- either define all constructor's arguments explicitly
- or use the new `Cookie::create()` factory

Commits
-------

9493cfd [HttpFoundation] make cookies auto-secure when passing them $secure=null + plan to make it and samesite=lax the defaults in 5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants