lgro...@hephaestos.ovh.adullact.org
unread,Nov 20, 2020, 10:51:55 AM11/20/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to openmairie...@googlegroups.com
Author: lgroleau
Date: 2020-11-20 16:51:53 +0100 (Fri, 20 Nov 2020)
New Revision: 4665
Modified:
openmairie_exemple/branches/prop0073-gestion_session/core/om_application.class.php
Log:
ajout redirection https integree, et nouveau parametre secure_cookie pour separer la gstion du cookie securise
Modified: openmairie_exemple/branches/prop0073-gestion_session/core/om_application.class.php
===================================================================
--- openmairie_exemple/branches/prop0073-gestion_session/core/om_application.class.php 2020-11-20 10:44:31 UTC (rev 4664)
+++ openmairie_exemple/branches/prop0073-gestion_session/core/om_application.class.php 2020-11-20 15:51:53 UTC (rev 4665)
@@ -560,6 +560,15 @@
$this->setTitle($title);
$this->setRight($right);
+ // redirection HTTPS si https obligatoire
+ if ( ( $this->get_https_mandatory() === true )
+ && (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === "off") ) {
+ $location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+ header('HTTP/1.1 301 Moved Permanently');
+ header('Location: ' . $location);
+ exit;
+ }
+
// Pour les connexions anonymes
if ($this->flag == "anonym") {
//
@@ -1020,7 +1029,7 @@
"lifetime" => $this->get_session_lifetime(),
"path" => "/" ,
"domain" => "",
- "secure" => $this->get_https_mandatory(),
+ "secure" => $this->get_secure_cookie(),
"httponly" => true,
"samesite" => "Strict", // Strict | Lax
);
@@ -1037,7 +1046,7 @@
}
// Rappel de la session
- @session_start();
+ @session_start();
// Regénération de l'indetifiant de session pour sécurisation
//
@@ -3418,8 +3427,8 @@
// comme attribut de om_application (framework) ou de utils (application).
$session_name = $this->_session_name;
}
- // Si on est en mode https obligatoire
- if ( $this->get_https_mandatory() === true ) {
+ // Si on est en mode secure_cookie
+ if ( $this->get_secure_cookie() === true ) {
// si le préfixe du cookie n'est pas déjà __Host- ou __Secure-
if ( ( substr($session_name, 0, 7) != "__Host-" )
|| ( substr($session_name, 0, 9) != "__Secure-" ) ) {
@@ -3470,6 +3479,13 @@
* @var mixed Configuration niveau framework.
*/
protected $_https_mandatory = false;
+
+ /**
+ * Gestion du mode secure cookie
+ *
+ * @var mixed Configuration niveau framework.
+ */
+ protected $_secure_cookie = false;
/**
* Gestion du mode HTTPS obligatoire
@@ -3492,6 +3508,28 @@
// comme attribut de om_application (framework) ou de utils (application).
return $this->_https_mandatory;
}
+
+ /**
+ * Gestion du mode HTTPS obligatoire
+ *
+ * L'objectif ici est d'avoir trois niveaux de configuration pour cet élément :
+ * framework, application et instance. Voici l'ordre de préférence si les trois
+ * niveaux sont configurés : instance > application > framework.
+ *
+ *
+ * @return mixed
+ */
+ function get_secure_cookie() {
+ // On récupère le paramètre depuis la configuration, si la valeur n'est
+ // pas nulle cela signifie qu'une configuration instance a été spécifiée
+ // par config.inc.php (et pas par om_parametre pas encore lue)
+ if ($this->getParameter("secure_cookie") !== null) {
+ return $this->getParameter("secure_cookie");
+ }
+ // On retourne ici la configuration framework ou application spécifiée
+ // comme attribut de om_application (framework) ou de utils (application).
+ return $this->_secure_cookie;
+ }
/**
* Gestion du mode de gestion des permissions.