Skip to content

Commit dd521f2

Browse files
Code review
1 parent 098ff7d commit dd521f2

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lib/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ exports.Definitions = class {
295295
segment = `${segment}; SameSite=${definition.isSameSite}`;
296296
}
297297

298-
if (definition.isPartitioned && definition.isSecure && definition.isSameSite === 'None') {
298+
if (definition.isPartitioned) {
299+
if (!definition.isSecure || definition.isSameSite !== 'None') {
300+
throw Boom.badImplementation('Partitioned flag can only be used with secure SameSite=None cookies')
301+
}
299302
segment = `${segment}; Partitioned`;
300303
}
301304

test/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,18 +1056,25 @@ describe('Definitions', () => {
10561056
expect(header[0]).to.equal('sid=fihfieuhr9384hf; Secure; HttpOnly; SameSite=None; Partitioned');
10571057
});
10581058

1059-
it('ignores partitioned option if not secure', async () => {
1059+
it('throws error if partitioned option if not secure', async () => {
10601060

10611061
const definitions = new Statehood.Definitions();
1062-
const header = await definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isPartitioned: true, isSecure: false, isHttpOnly: true, isSameSite: 'None' } });
1063-
expect(header[0]).to.equal('sid=fihfieuhr9384hf; HttpOnly; SameSite=None');
1062+
const result = await definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isPartitioned: true, isSecure: false, isHttpOnly: true, isSameSite: 'None' } });
1063+
expect(result.message).to.equal('Partitioned cookies must be secure');
10641064
});
10651065

1066-
it('ignores partitioned option if not SameSite=None', async () => {
1066+
it('throws error if partitioned option if not SameSite=None', async () => {
10671067

10681068
const definitions = new Statehood.Definitions();
1069-
const header = await definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isPartitioned: true, isSecure: true, isHttpOnly: true, isSameSite: 'Lax' } });
1070-
expect(header[0]).to.equal('sid=fihfieuhr9384hf; Secure; HttpOnly; SameSite=Lax');
1069+
const result = await definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isPartitioned: true, isSecure: true, isHttpOnly: true, isSameSite: 'Lax' } });
1070+
expect(result.message).to.equal('Partitioned cookies must have SameSite=None');
1071+
});
1072+
1073+
it('throws error if partitioned option if not secure and not SameSite=None', async () => {
1074+
1075+
const definitions = new Statehood.Definitions();
1076+
const result = await definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isPartitioned: true, isSecure: false, isHttpOnly: true, isSameSite: 'Lax' } });
1077+
expect(result.message).to.equal('Partitioned cookies must be secure and have SameSite=None');
10711078
});
10721079
});
10731080

0 commit comments

Comments
 (0)