Skip to content

Commit 408229e

Browse files
alexop1000dougwilson
authored andcommitted
Add "partitioned" to cookie options
fixes #961 closes #966
1 parent 50e1429 commit 408229e

File tree

6 files changed

+60
-2
lines changed

6 files changed

+60
-2
lines changed

HISTORY.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
unreleased
22
==========
33

4+
* Add `partitioned` to `cookie` options
45
* Add `priority` to `cookie` options
56
* Fix handling errors from setting cookie
67
* Support any type in `secret` that `crypto.createHmac` supports
7-
* deps: cookie@0.5.0
8+
* deps: cookie@0.6.0
89
- Fix `expires` option to reject invalid dates
910
- perf: improve default decode speed
1011
- perf: remove slow string split in parse

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ no maximum age is set.
8989
**Note** If both `expires` and `maxAge` are set in the options, then the last one
9090
defined in the object is what is used.
9191

92+
##### cookie.partitioned
93+
94+
Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
95+
attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not.
96+
By default, the `Partitioned` attribute is not set.
97+
98+
**Note** This is an attribute that has not yet been fully standardized, and may
99+
change in the future. This also means many clients may ignore this attribute until
100+
they understand it.
101+
102+
More information about can be found in [the proposal](https://github.com/privacycg/CHIPS).
103+
92104
##### cookie.path
93105

94106
Specifies the value for the `Path` `Set-Cookie`. By default, this is set to `'/'`, which
@@ -1003,6 +1015,7 @@ On Windows, use the corresponding command;
10031015
[MIT](LICENSE)
10041016

10051017
[rfc-6265bis-03-4.1.2.7]: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
1018+
[rfc-cutler-httpbis-partitioned-cookies]: https://tools.ietf.org/html/draft-cutler-httpbis-partitioned-cookies/
10061019
[rfc-west-cookie-priority-00-4.1]: https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1
10071020
[ci-image]: https://badgen.net/github/checks/expressjs/session/master?label=ci
10081021
[ci-url]: https://github.com/expressjs/session/actions?query=workflow%3Aci

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"repository": "expressjs/session",
1111
"license": "MIT",
1212
"dependencies": {
13-
"cookie": "0.5.0",
13+
"cookie": "0.6.0",
1414
"cookie-signature": "1.0.7",
1515
"debug": "2.6.9",
1616
"depd": "~2.0.0",

session/cookie.js

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Cookie.prototype = {
117117
get data() {
118118
return {
119119
originalMaxAge: this.originalMaxAge,
120+
partitioned: this.partitioned,
120121
priority: this.priority
121122
, expires: this._expires
122123
, secure: this.secure

test/cookie.js

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ describe('new Cookie()', function () {
107107
})
108108
})
109109

110+
describe('partitioned', function () {
111+
it('should set partitioned', function () {
112+
var cookie = new Cookie({ partitioned: true })
113+
114+
assert.strictEqual(cookie.partitioned, true)
115+
})
116+
})
117+
110118
describe('path', function () {
111119
it('should set path', function () {
112120
var cookie = new Cookie({ path: '/foo' })

test/session.js

+35
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,41 @@ describe('session()', function(){
22332233
})
22342234
})
22352235
})
2236+
2237+
describe('.partitioned', function () {
2238+
describe('by default', function () {
2239+
it('should not set partitioned attribute', function (done) {
2240+
var server = createServer()
2241+
2242+
request(server)
2243+
.get('/')
2244+
.expect(shouldSetCookieWithoutAttribute('connect.sid', 'Partitioned'))
2245+
.expect(200, done)
2246+
})
2247+
})
2248+
2249+
describe('when "false"', function () {
2250+
it('should not set partitioned attribute', function (done) {
2251+
var server = createServer({ cookie: { partitioned: false } })
2252+
2253+
request(server)
2254+
.get('/')
2255+
.expect(shouldSetCookieWithoutAttribute('connect.sid', 'Partitioned'))
2256+
.expect(200, done)
2257+
})
2258+
})
2259+
2260+
describe('when "true"', function () {
2261+
it('should set partitioned attribute', function (done) {
2262+
var server = createServer({ cookie: { partitioned: true } })
2263+
2264+
request(server)
2265+
.get('/')
2266+
.expect(shouldSetCookieWithAttribute('connect.sid', 'Partitioned'))
2267+
.expect(200, done)
2268+
})
2269+
})
2270+
})
22362271
})
22372272
})
22382273

0 commit comments

Comments
 (0)