Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ PHP NEWS
. Fixed a heap over-read in the interactive shell prompt when cli.prompt is
set to an empty string. (Ilia Alshanetsky)

- Session:
. Fixed session_start() continuing after a failed create_sid() when
session.use_strict_mode rejects the supplied ID. (Ilia Alshanetsky)

- Sockets:
. Fixed socket_select() silently truncating sets larger than FD_SETSIZE on
Windows. (David Carlier)
Expand Down
6 changes: 5 additions & 1 deletion ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,11 @@ static zend_result php_session_initialize(void) /* {{{ */
}
PS(id) = PS(mod)->s_create_sid(&PS(mod_data));
if (!PS(id)) {
PS(id) = php_session_create_id(NULL);
php_session_abort();
if (!EG(exception)) {
zend_throw_error(NULL, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
}
return FAILURE;
}
if (PS(use_cookies)) {
PS(send_cookie) = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
session_start() strict mode re-creation must abort when create_sid fails
--INI--
session.use_trans_sid=1
session.use_only_cookies=0
error_reporting=E_ALL & ~E_DEPRECATED
--EXTENSIONS--
session
--FILE--
<?php

class FailingHandler implements SessionHandlerInterface, SessionIdInterface, SessionUpdateTimestampHandlerInterface
{
public function open($path, $name): bool { return true; }
public function close(): bool { return true; }
public function read($id): string|false { return ''; }
public function write($id, $data): bool { return true; }
public function destroy($id): bool { return true; }
public function gc($max_lifetime): int|false { return 0; }
public function updateTimestamp($id, $data): bool { return true; }

public function create_sid(): string
{
throw new RuntimeException('create_sid failed');
}

public function validateId($id): bool
{
return false;
}
}

session_set_save_handler(new FailingHandler(), true);
session_id(str_repeat('a', 32));

try {
var_dump(session_start(['use_strict_mode' => true]));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

var_dump(session_status() === PHP_SESSION_ACTIVE);
var_dump(defined('SID'));

?>
--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!

bool(false)
bool(false)
Loading