Skip to content

Commit 36e9894

Browse files
committed
Add SameSite cookie attribute support in XUI
1 parent aef2c07 commit 36e9894

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

ui/commons/src/main/js/org/forgerock/commons/ui/common/SiteConfigurator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
1414
* Copyright 2011-2016 ForgeRock AS.
15+
* Portions copyright 2020-2026 3A Systems LLC.
1516
*/
1617

1718
define([
@@ -75,6 +76,7 @@ define([
7576

7677
conf.globalData.auth.cookieName = config.cookieName;
7778
conf.globalData.auth.cookieDomains = config.domains;
79+
conf.globalData.auth.cookieSameSite = config.cookieSameSite;
7880
};
7981

8082
obj.configurePage = function (route, params) {

ui/commons/src/main/js/org/forgerock/commons/ui/common/util/CookieHelper.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
1414
* Copyright 2011-2016 ForgeRock AS.
15+
* Portions copyright 2020-2026 3A Systems LLC.
1516
*/
1617

1718
define([
@@ -31,22 +32,25 @@ define([
3132
* @param {String} [path] - cookie path.
3233
* @param {String|String[]} [domain] - cookie domain(s).
3334
* @param {Boolean} [secure] - is cookie secure.
35+
* @param {String} [sameSite] - same site attribute.
3436
* @returns {String} created cookie.
3537
*/
36-
obj.createCookie = function (name, value, expirationDate, path, domain, secure) {
38+
obj.createCookie = function (name, value, expirationDate, path, domain, secure, sameSite) {
3739
var expirationDatePart,
3840
nameValuePart,
3941
pathPart,
4042
domainPart,
41-
securePart;
43+
securePart,
44+
sameSitePart;
4245

4346
expirationDatePart = expirationDate ? ";expires=" + expirationDate.toGMTString() : "";
4447
nameValuePart = name + "=" + value;
4548
pathPart = path ? ";path=" + path : "";
4649
domainPart = domain ? ";domain=" + domain : "";
4750
securePart = secure ? ";secure" : "";
51+
sameSitePart = sameSite ? ";SameSite=" + sameSite : "";
4852

49-
return nameValuePart + expirationDatePart + pathPart + domainPart + securePart;
53+
return nameValuePart + expirationDatePart + pathPart + domainPart + securePart + sameSitePart;
5054
};
5155

5256
/**
@@ -56,18 +60,19 @@ define([
5660
* @param {Date} [expirationDate] - cookie expiration date.
5761
* @param {String} [path] - cookie path.
5862
* @param {String|String[]} [domain] - cookie domain(s). Use empty array for creating host-only cookies.
63+
* @param {String} [sameSite] - cookie same site attribute.
5964
* @param {Boolean} [secure] - is cookie secure.
6065
*/
61-
obj.setCookie = function (name, value, expirationDate, path, domains, secure) {
66+
obj.setCookie = function (name, value, expirationDate, path, domains, secure, sameSite) {
6267
if (!_.isArray(domains)) {
6368
domains = [domains];
6469
}
6570

6671
if (domains.length === 0) {
67-
document.cookie = obj.createCookie(name, value, expirationDate, path, undefined, secure);
72+
document.cookie = obj.createCookie(name, value, expirationDate, path, undefined, secure, sameSite);
6873
} else {
6974
_.each(domains, function(domain) {
70-
document.cookie = obj.createCookie(name, value, expirationDate, path, domain, secure);
75+
document.cookie = obj.createCookie(name, value, expirationDate, path, domain, secure, sameSite);
7176
});
7277
}
7378
};

0 commit comments

Comments
 (0)