Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #26 - [Feature Request] Support of phasing out third-party cookies #27

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cometd-nodejs-server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ export interface Options {
sweepPeriod?: number;
timeout?: number;
// HTTP options.
browserCookieDomain?: string;
browserCookieHttpOnly?: boolean;
browserCookieMaxAge?: number;
browserCookieName?: string;
browserCookiePartitioned?: boolean;
browserCookiePath?: string;
browserCookieSameSite?: 'Strict' | 'Lax' | 'None';
browserCookieSecure?: boolean;
duplicateMetaConnectHttpResponseCode?: number;
Expand Down
15 changes: 15 additions & 0 deletions cometd-nodejs-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ module.exports = (() => {

function _generateCookie(cookieName, cookieValue) {
let result = cookieName + '=' + cookieValue;
const domain = _self.option('browserCookieDomain');
if (domain) {
result += '; Domain=' + domain;
}
const path = _self.option('browserCookiePath');
if (path) {
result += '; Path=' + path;
}
const maxAge = _self.option('browserCookieMaxAge');
if (maxAge) {
result += '; Max-Age=' + maxAge;
}
if (_self.option('browserCookieHttpOnly') === true) {
result += '; HttpOnly';
}
Expand All @@ -368,6 +380,9 @@ module.exports = (() => {
if (sameSite) {
result += '; SameSite=' + sameSite;
}
if (_self.option('browserCookiePartitioned') === true) {
result += '; Partitioned';
}
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"test": "mocha --exit --require ts-node/register --extension ts"
},
"devDependencies": {
"@types/mocha": ">=10.0.0",
"@types/node": ">=16.0.0",
"cometd": "^7.0.6",
"cometd-nodejs-client": "^1.4.0",
"mocha": ">=10.2.0",
"typescript": ">=5.0.0",
"ts-node": ">=10.9.0",
"@types/node": ">=16.0.0",
"@types/mocha": ">=10.0.0"
"typescript": ">=5.0.0"
}
}
35 changes: 35 additions & 0 deletions test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,41 @@ describe('server', () => {
'}]');
});

it('supports Partitioned cookie attribute', done => {
_server.options.browserCookiePath = '/';
_server.options.browserCookieSecure = true;
_server.options.browserCookiePartitioned = true;

http.request(newRequest(), r => {
receiveResponse(r, replies => {
const reply = replies[0];
assert.strictEqual(reply.successful, true);
const headers = r.headers;
for (let name in headers) {
if (headers.hasOwnProperty(name)) {
if (/^set-cookie$/i.test(name)) {
const values = headers[name] || [];
for (let i = 0; i < values.length; ++i) {
let value = values[i];
if (value.indexOf('Partitioned') >= 0 &&
value.indexOf('Path=/') >= 0 &&
value.indexOf('Secure') >= 0) {
done();
return;
}
}
}
}
}
done(new Error('missing Partitioned cookie attribute'));
});
}).end('[{' +
'"channel": "/meta/handshake",' +
'"version": "1.0",' +
'"supportedConnectionTypes": ["long-polling"]' +
'}]');
});

it('resends messages when connection is broken', done => {
const serverAck = require('../ack-extension');
_server.addExtension(new serverAck.AcknowledgedMessagesExtension());
Expand Down