Skip to content

Commit

Permalink
Add "partitioned" to cookie options
Browse files Browse the repository at this point in the history
fixes #961
closes #966
  • Loading branch information
alexop1000 authored and dougwilson committed Jan 28, 2024
1 parent 50e1429 commit 408229e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
unreleased
==========

* Add `partitioned` to `cookie` options
* Add `priority` to `cookie` options
* Fix handling errors from setting cookie
* Support any type in `secret` that `crypto.createHmac` supports
* deps: cookie@0.5.0
* deps: cookie@0.6.0
- Fix `expires` option to reject invalid dates
- perf: improve default decode speed
- perf: remove slow string split in parse
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ no maximum age is set.
**Note** If both `expires` and `maxAge` are set in the options, then the last one
defined in the object is what is used.

##### cookie.partitioned

Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not.
By default, the `Partitioned` attribute is not set.

**Note** This is an attribute that has not yet been fully standardized, and may
change in the future. This also means many clients may ignore this attribute until
they understand it.

More information about can be found in [the proposal](https://github.com/privacycg/CHIPS).

##### cookie.path

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

[rfc-6265bis-03-4.1.2.7]: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
[rfc-cutler-httpbis-partitioned-cookies]: https://tools.ietf.org/html/draft-cutler-httpbis-partitioned-cookies/
[rfc-west-cookie-priority-00-4.1]: https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1
[ci-image]: https://badgen.net/github/checks/expressjs/session/master?label=ci
[ci-url]: https://github.com/expressjs/session/actions?query=workflow%3Aci
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"repository": "expressjs/session",
"license": "MIT",
"dependencies": {
"cookie": "0.5.0",
"cookie": "0.6.0",
"cookie-signature": "1.0.7",
"debug": "2.6.9",
"depd": "~2.0.0",
Expand Down
1 change: 1 addition & 0 deletions session/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Cookie.prototype = {
get data() {
return {
originalMaxAge: this.originalMaxAge,
partitioned: this.partitioned,
priority: this.priority
, expires: this._expires
, secure: this.secure
Expand Down
8 changes: 8 additions & 0 deletions test/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ describe('new Cookie()', function () {
})
})

describe('partitioned', function () {
it('should set partitioned', function () {
var cookie = new Cookie({ partitioned: true })

assert.strictEqual(cookie.partitioned, true)
})
})

describe('path', function () {
it('should set path', function () {
var cookie = new Cookie({ path: '/foo' })
Expand Down
35 changes: 35 additions & 0 deletions test/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,41 @@ describe('session()', function(){
})
})
})

describe('.partitioned', function () {
describe('by default', function () {
it('should not set partitioned attribute', function (done) {
var server = createServer()

request(server)
.get('/')
.expect(shouldSetCookieWithoutAttribute('connect.sid', 'Partitioned'))
.expect(200, done)
})
})

describe('when "false"', function () {
it('should not set partitioned attribute', function (done) {
var server = createServer({ cookie: { partitioned: false } })

request(server)
.get('/')
.expect(shouldSetCookieWithoutAttribute('connect.sid', 'Partitioned'))
.expect(200, done)
})
})

describe('when "true"', function () {
it('should set partitioned attribute', function (done) {
var server = createServer({ cookie: { partitioned: true } })

request(server)
.get('/')
.expect(shouldSetCookieWithAttribute('connect.sid', 'Partitioned'))
.expect(200, done)
})
})
})
})
})

Expand Down

0 comments on commit 408229e

Please sign in to comment.