Skip to content

Prevent creating a new session until necessary - #2685

Merged
tvdijen merged 1 commit into
simplesamlphp:masterfrom
jornane:fix/no-new-session
Nov 25, 2026
Merged

tvdijen merged 1 commit into
simplesamlphp:masterfrom
jornane:fix/no-new-session

Conversation

@jornane

@jornane jornane commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Fix for #2684

Make $session in Auth\Simple nullable, and add getSession() function that will load the session if it was not set. Informative actions such as checking if the user is logged in will null check the session, and not call the function, to avoid starting a session. Actions that have side effects, such as redirecting to login, will use the function and thus start a session.

Split Session::getExistingSessionFromRequest from Session::getSessionFromRequest, to allow retrieving a session only if it already exists, but avoid creating one if one doesn't exist already.

@jornane
jornane force-pushed the fix/no-new-session branch 2 times, most recently from b5bd1d4 to d35c572 Compare September 17, 2026 19:56
@tvdijen
tvdijen requested a review from monkeyiq September 17, 2026 20:57
Make $session in Auth\Simple nullable, and add getSession() function
that will load the session if it was not set.  Informative actions
such as checking if the user is logged in will null check the session,
and not call the function, to avoid starting a session.  Actions that
have side effects, such as redirecting to login, will use the function
and thus start a session.

Split getSessionFromRequest into two functions, one that will create
a new session if one does not exist, and one that will return null if
a session does not exist.
@tvdijen
tvdijen merged commit 9586364 into simplesamlphp:master Nov 25, 2026
31 of 40 checks passed
tvdijen pushed a commit that referenced this pull request Nov 25, 2026
Make $session in Auth\Simple nullable, and add getSession() function
that will load the session if it was not set.  Informative actions
such as checking if the user is logged in will null check the session,
and not call the function, to avoid starting a session.  Actions that
have side effects, such as redirecting to login, will use the function
and thus start a session.

Split getSessionFromRequest into two functions, one that will create
a new session if one does not exist, and one that will return null if
a session does not exist.
tvdijen pushed a commit that referenced this pull request Nov 25, 2026
Make $session in Auth\Simple nullable, and add getSession() function
that will load the session if it was not set.  Informative actions
such as checking if the user is logged in will null check the session,
and not call the function, to avoid starting a session.  Actions that
have side effects, such as redirecting to login, will use the function
and thus start a session.

Split getSessionFromRequest into two functions, one that will create
a new session if one does not exist, and one that will return null if
a session does not exist.
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.

2 participants