Repository navigation
ext/session: Fix new empty sessions never being stored with lazy_write and strict mode #25433
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
Open
jorgsowa
wants to merge
1
commit into
php:PHP-8.6
Choose a base branch
from
jorgsowa:fix-session-lazy-write-new-sid-8.6
base: PHP-8.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
ext/session/tests/user_session_module/lazy_write_new_session_id_no_id.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| --TEST-- | ||
| lazy_write stores a new empty session when no ID is given | ||
| --EXTENSIONS-- | ||
| session | ||
| --INI-- | ||
| session.use_strict_mode=1 | ||
| session.lazy_write=1 | ||
| session.use_cookies=0 | ||
| session.cache_limiter= | ||
| --FILE-- | ||
| <?php | ||
| class Handler implements SessionHandlerInterface, SessionIdInterface, SessionUpdateTimestampHandlerInterface | ||
| { | ||
| private array $storage = []; | ||
|
|
||
| public function open($path, $name): bool { return true; } | ||
| public function close(): bool { return true; } | ||
| public function read($id): string|false { return $this->storage[$id] ?? ''; } | ||
| public function write($id, $data): bool { echo "write\n"; $this->storage[$id] = $data; return true; } | ||
| public function destroy($id): bool { return true; } | ||
| public function gc($max_lifetime): int|false { return 0; } | ||
| public function create_sid(): string { return bin2hex(random_bytes(16)); } | ||
| public function validateId($id): bool { return isset($this->storage[$id]); } | ||
| public function updateTimestamp($id, $data): bool { echo "updateTimestamp\n"; return true; } | ||
| } | ||
|
|
||
| session_set_save_handler(new Handler()); | ||
|
|
||
| session_start(); | ||
| $id = session_id(); | ||
| session_commit(); | ||
|
|
||
| session_id($id); | ||
| session_start(); | ||
| var_dump(session_id() === $id); | ||
| session_commit(); | ||
| ?> | ||
| --EXPECT-- | ||
| write | ||
| bool(true) | ||
| updateTimestamp |
44 changes: 44 additions & 0 deletions
44
ext/session/tests/user_session_module/lazy_write_new_session_id_rejected.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --TEST-- | ||
| lazy_write stores a new empty session when strict mode rejects the ID | ||
| --EXTENSIONS-- | ||
| session | ||
| --INI-- | ||
| session.use_strict_mode=1 | ||
| session.lazy_write=1 | ||
| session.use_cookies=0 | ||
| session.cache_limiter= | ||
| --FILE-- | ||
| <?php | ||
| class Handler implements SessionHandlerInterface, SessionIdInterface, SessionUpdateTimestampHandlerInterface | ||
| { | ||
| private array $storage = []; | ||
|
|
||
| public function open($path, $name): bool { return true; } | ||
| public function close(): bool { return true; } | ||
| public function read($id): string|false { return $this->storage[$id] ?? ''; } | ||
| public function write($id, $data): bool { echo "write\n"; $this->storage[$id] = $data; return true; } | ||
| public function destroy($id): bool { return true; } | ||
| public function gc($max_lifetime): int|false { return 0; } | ||
| public function create_sid(): string { return bin2hex(random_bytes(16)); } | ||
| public function validateId($id): bool { return isset($this->storage[$id]); } | ||
| public function updateTimestamp($id, $data): bool { echo "updateTimestamp\n"; return true; } | ||
| } | ||
|
|
||
| session_set_save_handler(new Handler()); | ||
|
|
||
| session_id('unknown'); | ||
| session_start(); | ||
| var_dump(session_id() !== 'unknown'); | ||
| $id = session_id(); | ||
| session_commit(); | ||
|
|
||
| session_id($id); | ||
| session_start(); | ||
| var_dump(session_id() === $id); | ||
| session_commit(); | ||
| ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| write | ||
| bool(true) | ||
| updateTimestamp | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this handler is identical to the one in lazy_write_new_session_id_no_id.phpt. Could merge both cases into a single test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I specifically put them into separate files to have simpler to understand different paths.