Skip to content

Commit 4368d97

Browse files
authored
Merge pull request #142 from arnivuo/master
Add isSameSite to schema
2 parents 74e8149 + e8d0e8d commit 4368d97

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The `'cookie`' scheme takes the following options:
2929
expired in the response and cleared. Defaults to `false`.
3030
- `keepAlive` - if `true`, automatically sets the session cookie after validation to extend the
3131
current session for a new `ttl` duration. Defaults to `false`.
32+
- `isSameSite` - if `false` omitted. Other options `Strict` or `Lax`. Defaults to `Strict`.
3233
- `isSecure` - if `false`, the cookie is allowed to be transmitted over insecure connections which
3334
exposes it to attacks. Defaults to `true`.
3435
- `isHttpOnly` - if `false`, the cookie will not include the 'HttpOnly' flag. Defaults to `true`.

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internals.schema = Joi.object({
3030
path: Joi.string().default('/'),
3131
clearInvalid: Joi.boolean().default(false),
3232
keepAlive: Joi.boolean().default(false),
33+
isSameSite: Joi.valid('Strict', 'Lax').allow(false).default('Strict'),
3334
isSecure: Joi.boolean().default(true),
3435
isHttpOnly: Joi.boolean().default(true),
3536
redirectTo: Joi.string().allow(false),
@@ -51,6 +52,7 @@ internals.implementation = function (server, options) {
5152
password: settings.password,
5253
isSecure: settings.isSecure, // Defaults to true
5354
path: settings.path,
55+
isSameSite: settings.isSameSite,
5456
isHttpOnly: settings.isHttpOnly, // Defaults to true
5557
clearInvalid: settings.clearInvalid,
5658
ignoreErrors: true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"devDependencies": {
2626
"code": "2.x.x",
27-
"hapi": "13.x.x",
27+
"hapi": "15.x.x",
2828
"lab": "10.x.x"
2929
},
3030
"scripts": {

test/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ describe('scheme', () => {
318318

319319
expect(res2.statusCode).to.equal(200);
320320
expect(res2.result).to.equal('logged-out');
321-
expect(res2.headers['set-cookie'][0]).to.equal('special=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; Domain=example.com; Path=/');
321+
expect(res2.headers['set-cookie'][0]).to.equal('special=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; SameSite=Strict; Domain=example.com; Path=/');
322322
done();
323323
});
324324
/* eslint-enable hapi/no-shadow-relaxed */
@@ -380,7 +380,7 @@ describe('scheme', () => {
380380
/* eslint-disable hapi/no-shadow-relaxed */
381381
server.inject({ method: 'GET', url: '/resource', headers: { cookie: 'special=' + cookie[1] } }, (res2) => {
382382

383-
expect(res2.headers['set-cookie'][0]).to.equal('special=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; Domain=example.com; Path=/');
383+
expect(res2.headers['set-cookie'][0]).to.equal('special=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; SameSite=Strict; Domain=example.com; Path=/');
384384
expect(res2.statusCode).to.equal(401);
385385
done();
386386
});
@@ -1600,7 +1600,7 @@ describe('scheme', () => {
16001600
server.inject({ url: '/', headers: { cookie: 'sid=123456' } }, (res) => {
16011601

16021602
expect(res.statusCode).to.equal(401);
1603-
expect(res.headers['set-cookie'][0]).to.equal('sid=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; Path=/');
1603+
expect(res.headers['set-cookie'][0]).to.equal('sid=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; SameSite=Strict; Path=/');
16041604
done();
16051605
});
16061606
});

0 commit comments

Comments
 (0)