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.5] Adding Cookie SameSite support #18040

Merged
merged 1 commit into from
Feb 21, 2017
Merged
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
Adding Cookie SameSite support
  • Loading branch information
fernandobandeira committed Feb 21, 2017
commit 4216940c55ed801d653742f4ef4a93d251ad2e54
38 changes: 21 additions & 17 deletions src/Illuminate/Cookie/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,42 @@ class CookieJar implements JarContract
/**
* Create a new cookie instance.
*
* @param string $name
* @param string $value
* @param int $minutes
* @param string $path
* @param string $domain
* @param bool $secure
* @param bool $httpOnly
* @param string $name
* @param string $value
* @param int $minutes
* @param string $path
* @param string $domain
* @param bool $secure
* @param bool $httpOnly
* @param bool $raw
* @param string|null $sameSite
* @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 = false, $httpOnly = true, $raw = false, $sameSite = null)
{
list($path, $domain, $secure) = $this->getPathAndDomain($path, $domain, $secure);

$time = ($minutes == 0) ? 0 : Carbon::now()->getTimestamp() + ($minutes * 60);

return new Cookie($name, $value, $time, $path, $domain, $secure, $httpOnly);
return new Cookie($name, $value, $time, $path, $domain, $secure, $httpOnly, $raw, $sameSite);
}

/**
* Create a cookie that lasts "forever" (five years).
*
* @param string $name
* @param string $value
* @param string $path
* @param string $domain
* @param bool $secure
* @param bool $httpOnly
* @param string $name
* @param string $value
* @param string $path
* @param string $domain
* @param bool $secure
* @param bool $httpOnly
* @param bool $raw
* @param string|null $sameSite
* @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 = false, $httpOnly = true, $raw = false, $sameSite = null)
{
return $this->make($name, $value, 2628000, $path, $domain, $secure, $httpOnly);
return $this->make($name, $value, 2628000, $path, $domain, $secure, $httpOnly, $raw, $sameSite);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/Cookie/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ public function testCookiesAreCreatedWithProperOptions()
{
$cookie = $this->getCreator();
$cookie->setDefaultPathAndDomain('foo', 'bar');
$c = $cookie->make('color', 'blue', 10, '/path', '/domain', true, false);
$c = $cookie->make('color', 'blue', 10, '/path', '/domain', true, false, false, 'lax');
$this->assertEquals('blue', $c->getValue());
$this->assertFalse($c->isHttpOnly());
$this->assertTrue($c->isSecure());
$this->assertEquals('/domain', $c->getDomain());
$this->assertEquals('/path', $c->getPath());
$this->assertEquals('lax', $c->getSameSite());

$c2 = $cookie->forever('color', 'blue', '/path', '/domain', true, false);
$c2 = $cookie->forever('color', 'blue', '/path', '/domain', true, false, false, 'strict');
$this->assertEquals('blue', $c2->getValue());
$this->assertFalse($c2->isHttpOnly());
$this->assertTrue($c2->isSecure());
$this->assertEquals('/domain', $c2->getDomain());
$this->assertEquals('/path', $c2->getPath());
$this->assertEquals('strict', $c2->getSameSite());

$c3 = $cookie->forget('color');
$this->assertNull($c3->getValue());
Expand Down