Skip to content

ext/session: Abort strict-mode re-creation when create_sid() fails - #23847

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:promote/session-strict-recreate
Closed

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:promote/session-strict-recreate

Conversation

@iliaal

@iliaal iliaal commented Sep 22, 2026

Copy link
Copy Markdown
Member

Under session.use_strict_mode, when a save handler rejects the supplied ID, php_session_initialize() called s_create_sid() and quietly generated an internal ID when that failed. reset_id() then emitted Set-Cookie and defined SID for a session that goes on to fail, and when the internal generation failed too, PS(id) stayed NULL. This mirrors the abort the primary no-ID branch already performs. Same failure class as #23800, which covers session_regenerate_id().

When a save handler rejects the session ID under session.use_strict_mode,
php_session_initialize() papered over a failing s_create_sid() by generating
an internal ID and carrying on, so reset_id()'s Set-Cookie and SID side
effects ran for a session that never started, and a second failure left
PS(id) NULL. Mirror the primary no-ID branch: abort the session, throw when
no exception is pending, and return FAILURE. Sibling sites audited,
session_regenerate_id() and session_create_id() already NULL-check with
their own error paths.

@jorgsowa jorgsowa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks sensible but the exception message is invalid. Would be nice to improve it.


?>
--EXPECT--
Error: Session id must be a string

@jorgsowa jorgsowa Sep 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not very intuitive error message. Would be worth to investigate why proper exception Failed to create session ID is not propagated.

Edit: fixed negation mistake.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handler’s RuntimeException is retained as the previous exception by ps_create_sid_user(). “Failed to create session ID” only runs without a pending exception. I’d fix the misleading wrapper separately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants