-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.2] Set HttpOnly flag #12809
[5.2] Set HttpOnly flag #12809
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,13 @@ class CookieJar implements JarContract | |
protected $secure = false; | ||
|
||
/** | ||
* The default httpOnly setting (defaults to true). | ||
* | ||
* @var bool | ||
*/ | ||
protected $httpOnly = true; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems to be a TAB issue? |
||
* All of the cookies queued for sending. | ||
* | ||
* @var array | ||
|
@@ -48,9 +55,9 @@ class CookieJar implements JarContract | |
* @param bool $httpOnly | ||
* @return \Symfony\Component\HttpFoundation\Cookie | ||
*/ | ||
public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true) | ||
public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = null, $httpOnly = null) | ||
{ | ||
list($path, $domain, $secure) = $this->getPathAndDomain($path, $domain, $secure); | ||
list($path, $domain, $secure, $httpOnly) = $this->getPathAndDomain($path, $domain, $secure, $httpOnly); | ||
|
||
$time = ($minutes == 0) ? 0 : time() + ($minutes * 60); | ||
|
||
|
@@ -68,7 +75,7 @@ public function make($name, $value, $minutes = 0, $path = null, $domain = null, | |
* @param bool $httpOnly | ||
* @return \Symfony\Component\HttpFoundation\Cookie | ||
*/ | ||
public function forever($name, $value, $path = null, $domain = null, $secure = false, $httpOnly = true) | ||
public function forever($name, $value, $path = null, $domain = null, $secure = null, $httpOnly = null) | ||
{ | ||
return $this->make($name, $value, 2628000, $path, $domain, $secure, $httpOnly); | ||
} | ||
|
@@ -143,11 +150,12 @@ public function unqueue($name) | |
* @param string $path | ||
* @param string $domain | ||
* @param bool $secure | ||
* @param bool $httpOnly | ||
* @return array | ||
*/ | ||
protected function getPathAndDomain($path, $domain, $secure = false) | ||
protected function getPathAndDomain($path, $domain, $secure = null, $httpOnly = null) | ||
{ | ||
return [$path ?: $this->path, $domain ?: $this->domain, $secure ?: $this->secure]; | ||
return [$path ?: $this->path, $domain ?: $this->domain, isset($secure) ? $secure : $this->secure, isset($httpOnly) ? $httpOnly : $this->httpOnly]; | ||
} | ||
|
||
/** | ||
|
@@ -156,11 +164,12 @@ protected function getPathAndDomain($path, $domain, $secure = false) | |
* @param string $path | ||
* @param string $domain | ||
* @param bool $secure | ||
* @param bool $httpOnly | ||
* @return $this | ||
*/ | ||
public function setDefaultPathAndDomain($path, $domain, $secure = false) | ||
public function setDefaultPathAndDomain($path, $domain, $secure = false, $httpOnly = true) | ||
{ | ||
list($this->path, $this->domain, $this->secure) = [$path, $domain, $secure]; | ||
list($this->path, $this->domain, $this->secure, $this->httpOnly) = [$path, $domain, $secure, $httpOnly]; | ||
|
||
return $this; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
namespace Illuminate\Session\Middleware; | ||
|
||
use Closure; | ||
use Carbon\Carbon; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Session\SessionManager; | ||
|
@@ -178,9 +177,8 @@ protected function addCookieToResponse(Response $response, SessionInterface $ses | |
} | ||
|
||
if ($this->sessionIsPersistent($config = $this->manager->getSessionConfig())) { | ||
$response->headers->setCookie(new Cookie( | ||
$session->getName(), $session->getId(), $this->getCookieExpirationDate(), | ||
$config['path'], $config['domain'], Arr::get($config, 'secure', false) | ||
$response->headers->setCookie(cookie()->make( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't depending on Do we need to consider people using the Session Component outside of Laravel? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'v also update the helper function cookie(), so we can use it now to take the configuration values . |
||
$session->getName(), $session->getId(), $this->getCookieExpirationDate() | ||
)); | ||
} | ||
} | ||
|
@@ -204,7 +202,7 @@ protected function getCookieExpirationDate() | |
{ | ||
$config = $this->manager->getSessionConfig(); | ||
|
||
return $config['expire_on_close'] ? 0 : Carbon::now()->addMinutes($config['lifetime']); | ||
return $config['expire_on_close'] ? 0 : $config['lifetime']; | ||
} | ||
|
||
/** | ||
|
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.
As I mentioned in #12818 (comment)
Making this default to
true
while previously it's default tofalse
in a patch release should be consider as breaking change.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.
The default value was true, and it can be override by passing another value to make function. Now all we make that we read this value from session config
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.
How can you say that when the changelog clearly shows the opposite.
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.
When anyone upgrade from say
v5.2.24
tov5.2.25
(if this get accepted). People shouldn't be worry about any configuration change and everything should works as it was before.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.
OK that,s right . I,ll update the cookie service provider file to keep it as previously settings.