Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session Lost for CI 3.1.13 on Page Refresh #6248

Open
mertdogan opened this issue Nov 13, 2023 Discussed in #6247 · 4 comments
Open

Session Lost for CI 3.1.13 on Page Refresh #6248

mertdogan opened this issue Nov 13, 2023 Discussed in #6247 · 4 comments

Comments

@mertdogan
Copy link

Discussed in #6247

Originally posted by mertdogan November 14, 2023
Hi. I started a new CI project with CI 3.1.13.

When i refresh page everything on session lost (still on database table) and new session created.

I replaced my new system/library/session folder with CI 3.1.11 (ini_set('session.id', $params['cookie_name']); tricked) and everything works without problem and session not lost.

my simple code at controller is:

	public function test(){
		$this->load->library('session');
		var_dump(isset($_SESSION['x'])?$_SESSION['x']:null);
		$_SESSION['x']='123';
		var_dump($_SESSION['x']);
	}

when i refresh page for CI3.1.13 than NULL 123 occurs but when i load with CI3.1.11 123 123 occurs on second page load.

I test everything on stackoverflow but can't solve problem.

my php version is 7.1.19 on IIS and using database driver for session. This is my config setting:

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ODEME_PORTAL_COOKIE';
$config['sess_samesite'] = 'None';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'CI_SESSIONS';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix'   = Set a cookie name prefix if you need to avoid collisions
| 'cookie_domain'   = Set to .your-domain.com for site-wide cookies
| 'cookie_path'     = Typically will be a forward slash
| 'cookie_secure'   = Cookie will only be set if a secure HTTPS connection exists.
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
| 'cookie_samesite' = Cookie's samesite attribute (Lax, Strict or None)
|
| Note: These settings (with the exception of 'cookie_prefix' and
|       'cookie_httponly') will also affect sessions.
|
*/
$config['cookie_prefix']	= '';
$config['cookie_domain']	= '';
$config['cookie_path']		= '/';
$config['cookie_secure']	= FALSE;
$config['cookie_httponly'] 	= FALSE;
$config['cookie_samesite'] 	= 'None';

@plufz
Copy link

plufz commented Feb 12, 2024

I had a similiar (maybe same) issue with the session cookies not being set, being samesite none and secure none on a localhost with self-signed ssl cert. Even on localhost the browsers did not like that. Chrome did not set the cookie at all and Safari made it samesite lax. Now it works when I use mkcert in my docker dev environment and on my mac host, so I have a valid cert everywhere. And cookie secure set to true.

@bunglegrind
Copy link

I don't think it's an issue, I couldn't replicate it (see the aforementioned discussion).

@plufz
Copy link

plufz commented Feb 13, 2024

I don't think it's an issue, I couldn't replicate it (see the aforementioned discussion).

No, not an CI issue. It is just a matter of many browsers not accepting cookies with samesite none combined with non-secure (http or https self-signed cert). A configuration issue.

@privatecore
Copy link

privatecore commented Mar 19, 2024

@mertdogan check your log files -> you should have errors with this configuration:
https://github.com/bcit-ci/CodeIgniter/blob/3.1-stable/system/libraries/Session/Session.php#L183

also, take a look at this article:
https://web.dev/articles/samesite-cookies-explained#samesitenone_must_be_secure

in short: a session with SameSite=None without the Secure parameter will not be saved in the browser's cookie jar, so your session will be new with every page refresh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants