Welcome Guest, Not a member yet? Register   Sign In
Support SameSite cookie
#6

(This post was last modified: 03-27-2021, 07:52 AM by CINewb.)

Further to my comment above, I've since ditched the idea of extending the session class and have instead added the samesite cookie attribute to my core system file.  I know this is terrible practice but it was less messy than extending the session class, and I'm hoping the samesite attribute is included in a future patch/version, therefore rendering my change temporary.

I did this by modifying line 163 in /system/libraries/Session/Session.php from:

PHP Code:
setcookie(
    $this->_config['cookie_name'],
    session_id(),
    (empty($this->_config['cookie_lifetime']) ? time() + $this->_config['cookie_lifetime']),
    $this->_config['cookie_path'],
    $this->_config['cookie_domain'],
    $this->_config['cookie_secure'],
    TRUE
); 

to

PHP Code:
setcookie(
    $this->_config['cookie_name'],
    session_id(),
    [
    'expires' => (empty($this->_config['cookie_lifetime']) ? time() + $this->_config['cookie_lifetime']),
    'path' => $this->_config['cookie_path'],
    'domain' => $this->_config['cookie_domain'],
    'secure' => $this->_config['cookie_secure'],
    'httponly' => TRUE,
    'samesite' => 'Lax',
    ]
); 

Really the samesite attribute should be configurable rather than hardcoded, and again I realise changing core system files is generally not acceptable.  In our case I just want to set this attribute with as little fuss as possible, and hope for a more permanent solution in the future.

Note: The above also assumes you are on PHP 7.3 or higher.
Reply


Messages In This Thread
Support SameSite cookie - by nicojmb - 03-12-2021, 07:45 AM
RE: Support SameSite cookie - by InsiteFX - 03-12-2021, 05:56 PM
RE: Support SameSite cookie - by nicojmb - 03-17-2021, 09:24 AM
RE: Support SameSite cookie - by kenjis - 03-17-2021, 05:10 PM
RE: Support SameSite cookie - by CINewb - 03-22-2021, 08:57 AM
RE: Support SameSite cookie - by CINewb - 03-27-2021, 07:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB