Skip to content

Commit

Permalink
Fix issue with client-side detection of valid cookie domain
Browse files Browse the repository at this point in the history
  • Loading branch information
faf committed Dec 1, 2021
1 parent a956f85 commit 6a0c067
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/mibew/js/source/chat_popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,25 @@ var Mibew = Mibew || {};
*/
Mibew.Utils.createCookie = function(name, value, expires) {
if (navigator.cookieEnabled) {
var domain = /([^\.]+\.[^\.]+)$/.exec(document.location.hostname);
document.cookie = "" + name + "=" + value + "; "
+ "path=/; "
+ (document.location.protocol == 'https:' ? "SameSite=None; secure; " : '')
+ (domain ? ("domain=" + domain[1] + "; ") : '')
+ (expires ? ('expires=' + expires.toUTCString() + '; ') : '');
var domain_parts = document.location.hostname.split('.').reverse();
var domain = domain_parts[0];
var position = 0;
do {
document.cookie = "" + name + "=" + value + "; "
+ "path=/; "
+ (document.location.protocol == 'https:' ? "SameSite=None; secure; " : '')
+ "domain=" + (Mibew.Utils.cookiesDomain || domain) + "; "
+ (expires ? ('expires=' + expires.toUTCString() + '; ') : '');
if (Mibew.Utils.readCookie(name) == value) {
if (!Mibew.Utils.cookiesDomain) {
Mibew.Utils.cookiesDomain = domain;
}
}
else {
position++;
domain = domain_parts[position] + '.' + domain;
}
} while((position < domain_parts.length) && !Mibew.Utils.cookiesDomain);
}
};

Expand Down

0 comments on commit 6a0c067

Please sign in to comment.