Set sameSite value for llnglanguage cookie (#2605)

This commit is contained in:
Christophe Maudoux 2021-09-14 22:36:36 +02:00 committed by Maxime Besson
parent 80e37a41f2
commit a4e15ad9a9
7 changed files with 23 additions and 16 deletions

View File

@ -9,7 +9,7 @@
#
package Lemonldap::NG::Portal::Main::Run;
our $VERSION = '2.0.13';
our $VERSION = '2.0.14';
package Lemonldap::NG::Portal::Main;
@ -17,7 +17,10 @@ use strict;
use URI::Escape;
use URI;
use JSON;
use Lemonldap::NG::Common::Util qw(getPSessionID);
use Lemonldap::NG::Common::Util qw(
getPSessionID
getSameSite
);
has trOverCache => ( is => 'rw', default => sub { {} } );
@ -1039,6 +1042,9 @@ sub tplParams {
}
return (
MAIN_LOGO => $self->conf->{portalMainLogo},
LANGS => $self->conf->{showLanguages},
SAMESITE => getSameSite(),
SKIN => $self->getSkin($req),
PORTAL_URL => $self->conf->{portal},
SKIN_PATH => $portalPath . "skins",

View File

@ -217,7 +217,7 @@ sub activeSessions {
};
} keys %$sessions;
}
return $activeSessions;
}

View File

@ -208,10 +208,10 @@ getCookie = (cname) ->
return c
return ''
setCookie = (name, value, exdays) ->
setCookie = (name, value, samesite, exdays) ->
d = new Date()
d.setTime d.getTime() + exdays*86400000
document.cookie = "#{name}=#{value}; expires=#{d.toUTCString()}; path=/"
document.cookie = "#{name}=#{value}; expires=#{d.toUTCString()}; path=/; SameSite=#{samesite}"
# Function to change password using Ajax (instead of POST)
# NOT USED FOR NOW
@ -364,11 +364,11 @@ $(window).on 'load', () ->
console.log 'Selected lang ->', queryLang
if setCookieLang
console.log 'Set cookie lang ->', queryLang
setCookie 'llnglanguage', queryLang
setCookie 'llnglanguage', queryLang, datas['sameSite']
translatePage(queryLang)
else
console.log 'Selected lang ->', lang
setCookie 'llnglanguage', lang
setCookie 'llnglanguage', lang, datas['sameSite']
translatePage(lang)
# Build language icons
@ -378,7 +378,7 @@ $(window).on 'load', () ->
$('#languages').html langdiv
$('.langicon').on 'click', () ->
lang = $(this).attr 'title'
setCookie 'llnglanguage', lang
setCookie 'llnglanguage', lang, datas['sameSite']
translatePage lang
isAlphaNumeric = (chr) ->

View File

@ -223,11 +223,11 @@ LemonLDAP::NG Portal jQuery scripts
return '';
};
setCookie = function(name, value, exdays) {
setCookie = function(name, value, samesite, exdays) {
var d;
d = new Date();
d.setTime(d.getTime() + exdays * 86400000);
return document.cookie = name + "=" + value + "; expires=" + (d.toUTCString()) + "; path=/";
return document.cookie = name + "=" + value + "; expires=" + (d.toUTCString()) + "; path=/; SameSite=" + samesite;
};
datas = {};
@ -379,12 +379,12 @@ LemonLDAP::NG Portal jQuery scripts
console.log('Selected lang ->', queryLang);
if (setCookieLang) {
console.log('Set cookie lang ->', queryLang);
setCookie('llnglanguage', queryLang);
setCookie('llnglanguage', queryLang, datas['sameSite']);
}
translatePage(queryLang);
} else {
console.log('Selected lang ->', lang);
setCookie('llnglanguage', lang);
setCookie('llnglanguage', lang, datas['sameSite']);
translatePage(lang);
}
langdiv = '';
@ -396,7 +396,7 @@ LemonLDAP::NG Portal jQuery scripts
$('#languages').html(langdiv);
$('.langicon').on('click', function() {
lang = $(this).attr('title');
setCookie('llnglanguage', lang);
setCookie('llnglanguage', lang, datas['sameSite']);
return translatePage(lang);
});
isAlphaNumeric = function(chr) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -38,7 +38,8 @@
"minspechar": "<TMPL_VAR NAME="PPOLICY_MINSPECHAR" DEFAULT="0">"
},</TMPL_IF>
"enablePasswordDisplay":<TMPL_VAR NAME="ENABLE_PASSWORD_DISPLAY" DEFAULT="0">,
"dontStorePassword":<TMPL_VAR NAME="DONT_STORE_PASSWORD" DEFAULT="0">
"dontStorePassword":<TMPL_VAR NAME="DONT_STORE_PASSWORD" DEFAULT="0">,
"sameSite":"<TMPL_VAR NAME="SAMESITE">"
}
</script>