Skip to content

Commit 5af8848

Browse files
committed
Merging develop to master in preparation for 1.4.0 release.
2 parents c5fa923 + 81819ef commit 5af8848

9 files changed

+56
-21
lines changed

.travis.yml

+4-10
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,18 @@ env:
1212
matrix:
1313
fast_finish: true
1414
include:
15-
- php: 7.1
15+
- php: 7.3
1616
env:
1717
- DEPS=lowest
18-
- php: 7.1
18+
- php: 7.3
1919
env:
2020
- DEPS=latest
2121
- CS_CHECK=true
2222
- TEST_COVERAGE=true
23-
- php: 7.2
24-
env:
25-
- DEPS=lowest
26-
- php: 7.2
27-
env:
28-
- DEPS=latest
29-
- php: 7.3
23+
- php: 7.4
3024
env:
3125
- DEPS=lowest
32-
- php: 7.3
26+
- php: 7.4
3327
env:
3428
- DEPS=latest
3529

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 1.3.2 - TBD
5+
## 1.4.0 - 2020-06-17
66

77
### Added
88

9-
- Nothing.
9+
- [#3](https://github.com/mezzio/mezzio-session-cache/pull/3) adds support for SameSite cookies. By default, the SameSite attribute will be set to "Lax", but the value can be configured via the mezzio-session-cache.cookie_same_site configuration setting.
1010

1111
### Changed
1212

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
},
2424
"extra": {
2525
"branch-alias": {
26-
"dev-master": "1.3.x-dev",
27-
"dev-develop": "1.4.x-dev"
26+
"dev-master": "1.4.x-dev",
27+
"dev-develop": "1.5.x-dev"
2828
},
2929
"laminas": {
3030
"config-provider": "Mezzio\\Session\\Cache\\ConfigProvider"
3131
}
3232
},
3333
"require": {
34-
"php": "^7.1",
35-
"dflydev/fig-cookies": "^1.0.2 || ^2.0",
34+
"php": "^7.3",
35+
"dflydev/fig-cookies": "^2.0.1",
3636
"laminas/laminas-zendframework-bridge": "^1.0",
3737
"mezzio/mezzio-session": "^1.2",
3838
"psr/cache": "^1.0",

docs/book/v1/config.md

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This package allows configuring the following items:
88
- The session cookie path.
99
- The session cookie secure option.
1010
- The session cookie httponly option.
11+
- The session cookie SameSite attribute (since 1.4.0).
1112
- The cache limiter (which controls how resources using sessions are cached by the browser).
1213
- When the session expires.
1314
- When the resource using a session was last modified.
@@ -117,6 +118,23 @@ return [
117118
// by scripting languages, such as JavaScript.
118119
'cookie_http_only' => false,
119120

121+
// Available since 1.4.0
122+
//
123+
// Asserts that a cookie must not be sent with cross-origin requests,
124+
// providing some protection against cross-site request forgery attacks (CSRF).
125+
//
126+
// Allowed values:
127+
// - Strict: The browser sends the cookie only for same-site requests
128+
// (that is, requests originating from the same site that set the cookie).
129+
// If the request originated from a different URL than the current one,
130+
// no cookies with the SameSite=Strict attribute are sent.
131+
// - Lax: The cookie is withheld on cross-site subrequests, such as calls
132+
// to load images or frames, but is sent when a user navigates to the URL
133+
// from an external site, such as by following a link.
134+
// - None: The browser sends the cookie with both cross-site and same-site
135+
// requests.
136+
'cookie_same_site' => 'Lax',
137+
120138
// Governs the various cache control headers emitted when
121139
// a session cookie is provided to the client. Value may be one
122140
// of "nocache", "public", "private", or "private_no_expire";

docs/book/v1/manual.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ The following details the constructor of the `Mezzio\Session\Cache\CacheSessionP
3333
* @param bool $cookieHttpOnly Whether or not the cookie may be accessed
3434
* by client-side apis (e.g., Javascript). An http-only cookie cannot
3535
* be accessed by client-side apis.
36+
* @param string $cookieSameSite The same-site rule to apply to the persisted
37+
* cookie. Options include "Lax", "Strict", and "None".
38+
* Available since 1.4.0
3639
*
3740
* @todo reorder these arguments so they make more sense and are in an
3841
* order of importance
@@ -47,7 +50,8 @@ public function __construct(
4750
bool $persistent = false,
4851
string $cookieDomain = null,
4952
bool $cookieSecure = false,
50-
bool $cookieHttpOnly = false
53+
bool $cookieHttpOnly = false,
54+
string $cookieSameSite = 'Lax'
5155
) {
5256
```
5357

src/CacheSessionPersistence.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use DateTimeImmutable;
1515
use Dflydev\FigCookies\FigRequestCookies;
1616
use Dflydev\FigCookies\FigResponseCookies;
17+
use Dflydev\FigCookies\Modifier\SameSite;
1718
use Dflydev\FigCookies\SetCookie;
1819
use Mezzio\Session\Session;
1920
use Mezzio\Session\SessionCookiePersistenceInterface;
@@ -85,6 +86,9 @@ class CacheSessionPersistence implements SessionPersistenceInterface
8586
/** @var bool */
8687
private $cookieHttpOnly;
8788

89+
/** @var string */
90+
private $cookieSameSite;
91+
8892
/** @var false|string */
8993
private $lastModified;
9094

@@ -121,6 +125,8 @@ class CacheSessionPersistence implements SessionPersistenceInterface
121125
* @param bool $cookieHttpOnly Whether or not the cookie may be accessed
122126
* by client-side apis (e.g., Javascript). An http-only cookie cannot
123127
* be accessed by client-side apis.
128+
* @param string $cookieSameSite The same-site rule to apply to the persisted
129+
* cookie. Options include "Lax", "Strict", and "None".
124130
*
125131
* @todo reorder the constructor arguments
126132
*/
@@ -134,7 +140,8 @@ public function __construct(
134140
bool $persistent = false,
135141
string $cookieDomain = null,
136142
bool $cookieSecure = false,
137-
bool $cookieHttpOnly = false
143+
bool $cookieHttpOnly = false,
144+
string $cookieSameSite = 'Lax'
138145
) {
139146
$this->cache = $cache;
140147

@@ -151,6 +158,8 @@ public function __construct(
151158

152159
$this->cookieHttpOnly = $cookieHttpOnly;
153160

161+
$this->cookieSameSite = $cookieSameSite;
162+
154163
$this->cacheLimiter = in_array($cacheLimiter, self::SUPPORTED_CACHE_LIMITERS, true)
155164
? $cacheLimiter
156165
: 'nocache';
@@ -197,7 +206,8 @@ public function persistSession(SessionInterface $session, ResponseInterface $res
197206
->withDomain($this->cookieDomain)
198207
->withPath($this->cookiePath)
199208
->withSecure($this->cookieSecure)
200-
->withHttpOnly($this->cookieHttpOnly);
209+
->withHttpOnly($this->cookieHttpOnly)
210+
->withSameSite(SameSite::fromString($this->cookieSameSite));
201211

202212
$persistenceDuration = $this->getPersistenceDuration($session);
203213
if ($persistenceDuration) {

src/CacheSessionPersistenceFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __invoke(ContainerInterface $container)
3131
$cookiePath = $config['cookie_path'] ?? '/';
3232
$cookieSecure = $config['cookie_secure'] ?? false;
3333
$cookieHttpOnly = $config['cookie_http_only'] ?? false;
34+
$cookieSameSite = $config['cookie_same_site'] ?? 'Lax';
3435
$cacheLimiter = $config['cache_limiter'] ?? 'nocache';
3536
$cacheExpire = $config['cache_expire'] ?? 10800;
3637
$lastModified = $config['last_modified'] ?? null;
@@ -46,7 +47,8 @@ public function __invoke(ContainerInterface $container)
4647
$persistent,
4748
$cookieDomain,
4849
$cookieSecure,
49-
$cookieHttpOnly
50+
$cookieHttpOnly,
51+
$cookieSameSite
5052
);
5153
}
5254
}

test/CacheSessionPersistenceFactoryTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function testFactoryUsesSaneDefaultsForConstructorArguments()
5959
$this->assertAttributeSame(null, 'cookieDomain', $persistence);
6060
$this->assertAttributeSame(false, 'cookieSecure', $persistence);
6161
$this->assertAttributeSame(false, 'cookieHttpOnly', $persistence);
62+
$this->assertAttributeSame('Lax', 'cookieSameSite', $persistence);
6263
$this->assertAttributeSame('nocache', 'cacheLimiter', $persistence);
6364
$this->assertAttributeSame(10800, 'cacheExpire', $persistence);
6465
$this->assertAttributeNotEmpty('lastModified', $persistence);
@@ -79,6 +80,7 @@ public function testFactoryAllowsConfiguringAllConstructorArguments()
7980
'cookie_path' => '/api',
8081
'cookie_secure' => true,
8182
'cookie_http_only' => true,
83+
'cookie_same_site' => 'None',
8284
'cache_limiter' => 'public',
8385
'cache_expire' => 300,
8486
'last_modified' => $lastModified,
@@ -97,6 +99,7 @@ public function testFactoryAllowsConfiguringAllConstructorArguments()
9799
$this->assertAttributeSame('example.com', 'cookieDomain', $persistence);
98100
$this->assertAttributeSame(true, 'cookieSecure', $persistence);
99101
$this->assertAttributeSame(true, 'cookieHttpOnly', $persistence);
102+
$this->assertAttributeSame('None', 'cookieSameSite', $persistence);
100103
$this->assertAttributeSame('public', 'cacheLimiter', $persistence);
101104
$this->assertAttributeSame(300, 'cacheExpire', $persistence);
102105
$this->assertAttributeSame(

test/CacheSessionPersistenceTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use DateInterval;
1414
use DateTimeImmutable;
15+
use Dflydev\FigCookies\Modifier\SameSite;
1516
use Laminas\Diactoros\Response;
1617
use Mezzio\Session\Cache\CacheSessionPersistence;
1718
use Mezzio\Session\Cache\Exception;
@@ -275,6 +276,7 @@ public function testConstructorUsesDefaultsForOptionalArguments()
275276
$this->assertAttributeSame('/', 'cookiePath', $persistence);
276277
$this->assertAttributeSame(false, 'cookieSecure', $persistence);
277278
$this->assertAttributeSame(false, 'cookieHttpOnly', $persistence);
279+
$this->assertAttributeSame('Lax', 'cookieSameSite', $persistence);
278280
$this->assertAttributeSame('nocache', 'cacheLimiter', $persistence);
279281
$this->assertAttributeSame(10800, 'cacheExpire', $persistence);
280282
$this->assertAttributeNotEmpty('lastModified', $persistence);
@@ -307,7 +309,8 @@ public function testConstructorAllowsProvidingAllArguments($cacheLimiter)
307309
false,
308310
'example.com',
309311
true,
310-
true
312+
true,
313+
'None'
311314
);
312315

313316
$this->assertAttributeSame($this->cachePool->reveal(), 'cache', $persistence);
@@ -316,6 +319,7 @@ public function testConstructorAllowsProvidingAllArguments($cacheLimiter)
316319
$this->assertAttributeSame('example.com', 'cookieDomain', $persistence);
317320
$this->assertAttributeSame(true, 'cookieSecure', $persistence);
318321
$this->assertAttributeSame(true, 'cookieHttpOnly', $persistence);
322+
$this->assertAttributeSame('None', 'cookieSameSite', $persistence);
319323
$this->assertAttributeSame($cacheLimiter, 'cacheLimiter', $persistence);
320324
$this->assertAttributeSame(100, 'cacheExpire', $persistence);
321325
$this->assertAttributeSame(

0 commit comments

Comments
 (0)