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

Forces "secure" to be re-added to parsed cookies #1964

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions packages/browser-sync/lib/server/proxy-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ function rewriteCookies(rawCookie) {
pairs.push("HttpOnly");
}

// SameSite=None must be declared as secure
// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite#samesitenone_requires_secure
// @see https://chromestatus.com/feature/5633521622188032
if (
rawCookie.match(/[ ]secure(?:\;|$)/i) &&
rawCookie.match(/[ ]SameSite=None(?:\;|$)/i)
) {
pairs.push("secure");
}

return pairs.join("; ");
}

Expand Down
1 change: 1 addition & 0 deletions packages/browser-sync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"prettier": "prettier 'lib/**/*' 'examples/*' 'test/specs/**/*.js' --tab-width 4",
"prettier:fix": "npm run prettier -- --write",
"test": "npm run build && npm run env && npm run unit",
"test:watch": "npm run build && npm run env && mocha --recursive test/specs --watch",
"unit": "mocha --recursive test/specs --timeout 10000 --bail --exit",
"watch": "npm run build && npm run serve:fixtures",
"serve:fixtures": "node dist/bin test/fixtures -w --no-open"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// jscs:disable maximumLineLength

var rewriteCookies = require("../../../dist/server/proxy-utils").rewriteCookies;
var expect = require("chai").expect;

describe("rewriteCookies spec", function() {
it("Should honor secure directive on SameSite=None cookies", function() {
var cookies = [
"localization=US; path=/; expires=Fri, 03 Jun 2022 21:13:22 GMT; SameSite=Lax",
"localization=secure; path=/; expires=Fri, 03 Jun 2022 21:13:22 GMT; SameSite=Lax",
"storefront_digest=1234567; path=/; secure; HttpOnly; SameSite=None"
];

var result = cookies.reduce((aggregate, cookie) => {
aggregate.push(rewriteCookies(cookie));
return aggregate;
}, []);

expect(result).to.deep.equal([
"localization=US; path=/; expires=Fri, 03 Jun 2022 21:13:22 GMT; SameSite=Lax",
"localization=secure; path=/; expires=Fri, 03 Jun 2022 21:13:22 GMT; SameSite=Lax",
"storefront_digest=1234567; path=/; SameSite=None; HttpOnly; secure"
]);
});
});