-
Notifications
You must be signed in to change notification settings - Fork 7.9k
BUG-10807: session_regenerate_id fails to check results of validateId… #10813
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--TEST-- | ||
Bug #10807 (session_regenerate_id with custom handler and use_strict_mode generates three new session ids) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree this is a bit confusing at first... But "Bug #XXXXX" is for the old bugs.php.net bug IDs. For GitHub we use "GH-XXXXX". So in this case you should change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes made. Might I suggest that the docs at https://qa.php.net/write-test.php are updated to handle this. Re rebasing to the 8.1 branch, my fork doesn't have this branch and this has exceeded my github knowledge. Are you able to take this over for now? |
||
--EXTENSIONS-- | ||
session | ||
--INI-- | ||
html_errors=0 | ||
session.save_handler=files | ||
session.use_strict_mode=1 | ||
--FILE-- | ||
<?php | ||
|
||
/** | ||
* This class will return a number for the session id, incrementing each time a new | ||
* session is generated | ||
*/ | ||
class Bug10807SessionHandler implements SessionHandlerInterface, SessionIdInterface { | ||
|
||
private bool $fail_validation; | ||
private int $sid_counter; | ||
|
||
public function __construct() { | ||
$this->fail_validation = FALSE; | ||
$this->sid_counter = 1; | ||
|
||
session_set_save_handler($this, FALSE); | ||
} | ||
|
||
public function setFailValidation() { | ||
$this->fail_validation = TRUE; | ||
} | ||
|
||
public function create_sid() : string { | ||
return strval($this->sid_counter++); | ||
} | ||
|
||
public function validateId(string $id) : bool { | ||
|
||
if ($this->fail_validation && intval($id)< 4) { | ||
return FALSE; | ||
} | ||
|
||
return TRUE; | ||
|
||
} | ||
|
||
public function close(): bool { return TRUE; } | ||
public function destroy(string $id): bool { return TRUE; } | ||
public function gc(int $max_lifetime): int|false { return TRUE; } | ||
public function open(string $path, string $name): bool { return TRUE; } | ||
public function read(string $id): string|false { return ''; } | ||
public function write(string $id, string $data): bool { return TRUE; } | ||
|
||
} | ||
|
||
ob_start(); | ||
|
||
$save_handler = new Bug10807SessionHandler(); | ||
session_start(); //session id = 1 | ||
session_regenerate_id(); //session id = 2 | ||
var_dump(session_id()); | ||
|
||
$save_handler->setFailValidation(); | ||
session_regenerate_id(); //should invoke create_sid twice as session id 3 will be invalid | ||
var_dump(session_id()); | ||
|
||
?> | ||
--EXPECT-- | ||
string(1) "2" | ||
string(1) "4" |
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.
This change is definitely incorrect.
I know the method name is terrible, but
validateId()
MUST only returntrue
if a session with this ID already exists.Symfony seems to have hit that mistake too and fixed it: symfony/symfony#47843