Skip to content

Commit

Permalink
[core] add parameters for the session cookie, and is now httponly by …
Browse files Browse the repository at this point in the history
…default
  • Loading branch information
laurentj committed Apr 10, 2020
1 parent 4d94d77 commit 80a29b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/jelix/core/defaultconfig.ini.php
Expand Up @@ -408,6 +408,13 @@
; share the same php session
shared_session = off

; parameters for the session cookie
cookieSecure=off
cookieHttpOnly=on
cookieExpires=0
; only supported with php 7.3.0+. Possible values: None, Strict, Lax
cookieSameSite=

; indicate a session name for each applications installed with the same
; domain and basePath, if their respective sessions shouldn't be shared
name=
Expand Down
24 changes: 21 additions & 3 deletions lib/jelix/core/jSession.class.php
Expand Up @@ -33,9 +33,27 @@ public static function start(){
return false;
}

//make sure that the session cookie is only for the current application
if (!$params['shared_session'])
session_set_cookie_params ( 0 , jApp::urlBasePath());
$cookieOptions = array(
'path' => '/',
'secure' => $params['cookieSecure'], // true to send the cookie only on a secure channel
'httponly' => $params['cookieHttpOnly'],
'expires' => $params['cookieExpires']
);

if (!$params['shared_session']) {
//make sure that the session cookie is only for the current application
$cookieOptions['path'] = jApp::urlBasePath();
}

if (PHP_VERSION_ID < 70300) {
session_set_cookie_params($cookieOptions['expires'], $cookieOptions['path'], '', $cookieOptions['secure'], $cookieOptions['httponly']);
}
else {
if ($params['cookieSameSite'] != '') {
$cookieOptions['samesite'] = $params['cookieSameSite'];
}
session_set_cookie_params($cookieOptions);
}

if ($params['storage'] != '') {

Expand Down

0 comments on commit 80a29b5

Please sign in to comment.