Skip to content

webui/sso: don't start the session before config.php is loaded - #517

Open
krzsztf1 wants to merge 1 commit into
jsuto:masterfrom
krzsztf1:sso-session-start
Open

krzsztf1 wants to merge 1 commit into
jsuto:masterfrom
krzsztf1:sso-session-start

Conversation

@krzsztf1

Copy link
Copy Markdown
Contributor

Fixes the bug reported in #501 (closed, but still present on master). Follow-up to #500.

sso.php calls session_start() before require_once("config.php"). Since 7cdb016 (2017), config.php applies the session hardening (cookie_httponly, use_strict_mode, use_only_cookies, cookie_lifetime = SESSION_EXPIRY) and then starts the session itself. On the SSO entry point the session is already active by then, so PHP rejects all four ini_set() calls and the cookie falls back to php.ini defaults.

This is broader than #501 described: besides SESSION_EXPIRY, sessions created via SSO also lose the HttpOnly flag and strict mode.

Before (GET /sso.php without a cookie), plus 4 ini_set() warnings per request:

Set-Cookie: PHPSESSID=…; path=/

After, identical to GET /:

Set-Cookie: PHPSESSID=…; expires=…; Max-Age=3600; path=/; HttpOnly

The fix drops the early session_start(); config.php starts the session right after the ini settings, as on the index.php path. The new Session() / Registry::set() lines further down are now redundant but harmless since #500, so I left them to keep the diff minimal. Visible change for SSO users: their session cookie now expires after SESSION_EXPIRY, like for form logins.

Tested on piler 1.4.9 / PHP 8.5 / nginx by comparing the Set-Cookie headers of /sso.php and / before and after the change. I don't have NTLM configured, so the SSO login itself was not exercised; the change only touches code that runs before authentication.

sso.php calls session_start() before it requires config.php, but
config.php applies the session hardening first and only then starts
the session itself:

  ini_set('session.cookie_httponly', true);
  ini_set('session.use_strict_mode', 1);
  ini_set('session.use_only_cookies', 1);
  ini_set('session.cookie_lifetime', $config['SESSION_EXPIRY']);

PHP refuses to change session ini settings while a session is active,
so on the SSO entry point all four calls fail with

  Warning: ini_set(): Session ini settings cannot be changed when a
  session is active

and the cookie is issued with php.ini defaults instead. With a stock
php.ini that means no HttpOnly flag, no strict mode and no expiry.
PHP does not resend the session cookie on later requests, so the
weaker cookie stays in use for the whole session.

config.php starts the session right after these settings, so the
early call is not needed. Removing it makes sso.php behave like
index.php.
@krzsztf1
krzsztf1 requested a review from jsuto as a code owner October 15, 2026 16:31
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

Successfully merging this pull request may close these issues.

1 participant