Skip to content

Commit 001ca62

Browse files
fix: use SameSite=Strict by default
In order to remove the following warning in Chrome: A cookie associated with a cross-site resource at ... was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. Please note that the cookie will be disabled by default in Engine.IO v4, see a374471
1 parent da851ec commit 001ca62

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/server.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ Server.prototype.handshake = function (transportName, req) {
323323
headers['Set-Cookie'] = cookieMod.serialize(self.cookie, id,
324324
{
325325
path: self.cookiePath,
326-
httpOnly: self.cookiePath ? self.cookieHttpOnly : false
326+
httpOnly: self.cookiePath ? self.cookieHttpOnly : false,
327+
sameSite: true
327328
});
328329
});
329330
}

test/server.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('server', function () {
117117
expect(err).to.be(null);
118118
// hack-obtain sid
119119
var sid = res.text.match(/"sid":"([^"]+)"/)[1];
120-
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/; HttpOnly');
120+
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/; HttpOnly; SameSite=Strict');
121121
done();
122122
});
123123
});
@@ -130,7 +130,7 @@ describe('server', function () {
130130
.end(function (err, res) {
131131
expect(err).to.be(null);
132132
var sid = res.text.match(/"sid":"([^"]+)"/)[1];
133-
expect(res.headers['set-cookie'][0]).to.be('woot=' + sid + '; Path=/; HttpOnly');
133+
expect(res.headers['set-cookie'][0]).to.be('woot=' + sid + '; Path=/; HttpOnly; SameSite=Strict');
134134
done();
135135
});
136136
});
@@ -143,7 +143,7 @@ describe('server', function () {
143143
.end(function (err, res) {
144144
expect(err).to.be(null);
145145
var sid = res.text.match(/"sid":"([^"]+)"/)[1];
146-
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/custom; HttpOnly');
146+
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/custom; HttpOnly; SameSite=Strict');
147147
done();
148148
});
149149
});
@@ -156,7 +156,7 @@ describe('server', function () {
156156
.end(function (err, res) {
157157
expect(err).to.be(null);
158158
var sid = res.text.match(/"sid":"([^"]+)"/)[1];
159-
expect(res.headers['set-cookie'][0]).to.be('io=' + sid);
159+
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; SameSite=Strict');
160160
done();
161161
});
162162
});
@@ -169,7 +169,7 @@ describe('server', function () {
169169
.end(function (err, res) {
170170
expect(err).to.be(null);
171171
var sid = res.text.match(/"sid":"([^"]+)"/)[1];
172-
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/; HttpOnly');
172+
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/; HttpOnly; SameSite=Strict');
173173
done();
174174
});
175175
});
@@ -182,7 +182,7 @@ describe('server', function () {
182182
.end(function (err, res) {
183183
expect(err).to.be(null);
184184
var sid = res.text.match(/"sid":"([^"]+)"/)[1];
185-
expect(res.headers['set-cookie'][0]).to.be('io=' + sid);
185+
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; SameSite=Strict');
186186
done();
187187
});
188188
});
@@ -195,7 +195,7 @@ describe('server', function () {
195195
.end(function (err, res) {
196196
expect(err).to.be(null);
197197
var sid = res.text.match(/"sid":"([^"]+)"/)[1];
198-
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/');
198+
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/; SameSite=Strict');
199199
done();
200200
});
201201
});
@@ -208,7 +208,7 @@ describe('server', function () {
208208
.end(function (err, res) {
209209
expect(err).to.be(null);
210210
var sid = res.text.match(/"sid":"([^"]+)"/)[1];
211-
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/; HttpOnly');
211+
expect(res.headers['set-cookie'][0]).to.be('io=' + sid + '; Path=/; HttpOnly; SameSite=Strict');
212212
done();
213213
});
214214
});

0 commit comments

Comments
 (0)