mirror of
https://github.com/Mibew/mibew.git
synced 2024-11-15 00:24:12 +03:00
Fix issue with client-side detection of valid cookie domain
See https://mibew.org/forums/index.php/topic,192324.msg200169.html
This commit is contained in:
parent
a956f85fc7
commit
6a0c067cef
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user