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

Skip to content

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

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

Merged
merged 1 commit into from
Sep 26, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Sep 11, 2018

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

@nicolas-grekas nicolas-grekas added this to the next milestone Sep 11, 2018
@nicolas-grekas nicolas-grekas changed the title [HttpFoundation] make cookies auto-secure by passing them $secure = null [HttpFoundation] make cookies auto-secure when passing them $secure = null Sep 11, 2018
@nicolas-grekas nicolas-grekas force-pushed the http-cookie-secure-auto branch 2 times, most recently from 69d8d9a to 1535093 Compare September 11, 2018 20:21
@nicolas-grekas
Copy link
Member Author

This PR now goes one step further and creates a path to change the default "secure" setting on new Cookie instances. The goal is to make it go from the current false to the new null, so that cookies are secure by default in 5.0, when they're created on an HTTPS connection.
Makes sense?

@nicolas-grekas nicolas-grekas force-pushed the http-cookie-secure-auto branch 2 times, most recently from 774c256 to f0a3863 Compare September 11, 2018 20:35
Copy link

@DavidGarciaCat DavidGarciaCat left a comment

Choose a reason for hiding this comment

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

This PR makes sense to me, although I must say that this is the 1st PR that I review on this repository. Thanks, @nicolas-grekas to consider this update after discuss it on the issue.

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

Missing some new tests

@@ -72,15 +73,19 @@ public static function fromString($cookie, $decode = false)
* @param int|string|\DateTimeInterface $expire The time the cookie expires
* @param string $path The path on the server in which the cookie will be available on
* @param string|null $domain The domain that the cookie is available to
* @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client
* @param bool|null $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client or null to set it later using {@see setSecureDefault()}
Copy link
Member

Choose a reason for hiding this comment

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

If think the most interesting bit to add is the auto-enabling feature (the setSecureDefault() is not that interesting if you ask me)

@nicolas-grekas nicolas-grekas changed the title [HttpFoundation] make cookies auto-secure when passing them $secure = null [HttpFoundation] make cookies auto-secure when passing them $secure=null + plan to make it and samesite=lax the defaults in 5.0 Sep 14, 2018
@nicolas-grekas nicolas-grekas force-pushed the http-cookie-secure-auto branch 2 times, most recently from ee1837f to a94f569 Compare September 17, 2018 13:39
if (null !== $this->sessionOptions) {
foreach ($this->sessionOptions as $k => $v) {
if (0 === strpos($k, 'cookie_')) {
$params[substr($k, 7)] = $v;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 💯

@nicolas-grekas
Copy link
Member Author

Tests added.

Status: needs review

@nicolas-grekas
Copy link
Member Author

Oh, and there is one more step now: samesite will turn to "lax" by default in Symfony 5!

…ull + plan to make it and samesite=lax the defaults in 5.0
@fabpot
Copy link
Member

fabpot commented Sep 26, 2018

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 9493cfd into symfony:master Sep 26, 2018
fabpot added a commit that referenced this pull request 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
@nicolas-grekas nicolas-grekas deleted the http-cookie-secure-auto branch October 2, 2018 14:04
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
chalasr added a commit that referenced this pull request Sep 10, 2023
…on (derrabus)

This PR was merged into the 6.4 branch.

Discussion
----------

[PsrHttpMessageBridge] Remove `Cookie::create()` detection

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

This method exists since #28447 (Symfony 4.2)

Commits
-------

94e75e6 [PsrHttpMessageBridge] Remove Cookie::create() detection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants