Skip to content
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] Reworked pull request #12809 #12842

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/Illuminate/Cookie/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class CookieJar implements JarContract
*/
protected $secure = false;

/**
* The default httpOnly setting (defaults to true).
*
* @var bool
*/
protected $httpOnly = true;

/**
* All of the cookies queued for sending.
*
Expand All @@ -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);

Expand All @@ -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);
}
Expand Down Expand Up @@ -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];
}

/**
Expand All @@ -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 = null, $httpOnly = null)
{
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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Cookie/CookieServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Cookie;

use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;

class CookieServiceProvider extends ServiceProvider
Expand All @@ -16,7 +17,7 @@ public function register()
$this->app->singleton('cookie', function ($app) {
$config = $app['config']['session'];

return (new CookieJar)->setDefaultPathAndDomain($config['path'], $config['domain'], $config['secure']);
return (new CookieJar)->setDefaultPathAndDomain($config['path'], $config['domain'], $config['secure'], Arr::get($config, 'http_only', true));
});
}
}
7 changes: 3 additions & 4 deletions src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Illuminate\Foundation\Http\Middleware;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Foundation\Application;
use Symfony\Component\HttpFoundation\Cookie;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Session\TokenMismatchException;

Expand Down Expand Up @@ -133,9 +133,8 @@ protected function addCookieToResponse($request, $response)
$config = config('session');

$response->headers->setCookie(
new Cookie(
'XSRF-TOKEN', $request->session()->token(), time() + 60 * 120,
$config['path'], $config['domain'], $config['secure'], false
cookie()->make(
'XSRF-TOKEN', $request->session()->token(), 120, null, null, null, Arr::get($config, 'http_only', false)
)
);

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function config_path($path = '')
* @param bool $httpOnly
* @return \Symfony\Component\HttpFoundation\Cookie
*/
function cookie($name = null, $value = null, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)
function cookie($name = null, $value = null, $minutes = 0, $path = null, $domain = null, $secure = null, $httpOnly = null)
{
$cookie = app(CookieFactory::class);

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Session/Middleware/StartSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ 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)
$config['path'], $config['domain'], Arr::get($config, 'secure', false), Arr::get($config, 'http_only', true)
));
}
}
Expand Down