框架升级及修复升级后的bug
This commit is contained in:
+31
-5
@@ -24,10 +24,21 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
|
||||
{
|
||||
private string $sessionName;
|
||||
private string $prefetchId;
|
||||
private string $prefetchData;
|
||||
private string|false $prefetchData;
|
||||
private ?\Throwable $prefetchError = null;
|
||||
private ?string $newSessionId = null;
|
||||
private string $igbinaryEmptyData;
|
||||
|
||||
public function __serialize(): array
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot serialize '.static::class);
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot unserialize '.static::class);
|
||||
}
|
||||
|
||||
public function open(string $savePath, string $sessionName): bool
|
||||
{
|
||||
$this->sessionName = $sessionName;
|
||||
@@ -38,12 +49,15 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create_sid(): string
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function create_sid()
|
||||
{
|
||||
return session_create_id() ?: throw new \RuntimeException('Unable to create a session ID.');
|
||||
}
|
||||
|
||||
abstract protected function doRead(#[\SensitiveParameter] string $sessionId): string;
|
||||
abstract protected function doRead(#[\SensitiveParameter] string $sessionId): string|false;
|
||||
|
||||
abstract protected function doWrite(#[\SensitiveParameter] string $sessionId, string $data): bool;
|
||||
|
||||
@@ -51,20 +65,32 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
|
||||
|
||||
public function validateId(#[\SensitiveParameter] string $sessionId): bool
|
||||
{
|
||||
$this->prefetchData = $this->read($sessionId);
|
||||
// Reporting a failed read as an invalid ID would make PHP issue a new ID and cookie, orphaning the session.
|
||||
// Keep the ID instead and let the failure surface from read().
|
||||
try {
|
||||
$this->prefetchData = $this->read($sessionId);
|
||||
} catch (\Throwable $e) {
|
||||
$this->prefetchData = false;
|
||||
$this->prefetchError = $e;
|
||||
}
|
||||
$this->prefetchId = $sessionId;
|
||||
|
||||
return '' !== $this->prefetchData;
|
||||
}
|
||||
|
||||
public function read(#[\SensitiveParameter] string $sessionId): string
|
||||
public function read(#[\SensitiveParameter] string $sessionId): string|false
|
||||
{
|
||||
if (isset($this->prefetchId)) {
|
||||
$prefetchId = $this->prefetchId;
|
||||
$prefetchData = $this->prefetchData;
|
||||
$prefetchError = $this->prefetchError;
|
||||
unset($this->prefetchId, $this->prefetchData);
|
||||
$this->prefetchError = null;
|
||||
|
||||
if ($prefetchId === $sessionId || '' === $prefetchData) {
|
||||
if ($prefetchError) {
|
||||
throw $prefetchError;
|
||||
}
|
||||
$this->newSessionId = '' === $prefetchData ? $sessionId : null;
|
||||
|
||||
return $prefetchData;
|
||||
|
||||
Vendored
+18
-3
@@ -24,6 +24,16 @@ class MarshallingSessionHandler implements \SessionHandlerInterface, \SessionUpd
|
||||
) {
|
||||
}
|
||||
|
||||
public function __serialize(): array
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
|
||||
public function open(string $savePath, string $name): bool
|
||||
{
|
||||
return $this->handler->open($savePath, $name);
|
||||
@@ -34,7 +44,10 @@ class MarshallingSessionHandler implements \SessionHandlerInterface, \SessionUpd
|
||||
return $this->handler->close();
|
||||
}
|
||||
|
||||
public function create_sid(): string
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function create_sid()
|
||||
{
|
||||
return session_create_id() ?: throw new \RuntimeException('Unable to create a session ID.');
|
||||
}
|
||||
@@ -49,9 +62,11 @@ class MarshallingSessionHandler implements \SessionHandlerInterface, \SessionUpd
|
||||
return $this->handler->gc($maxlifetime);
|
||||
}
|
||||
|
||||
public function read(#[\SensitiveParameter] string $sessionId): string
|
||||
public function read(#[\SensitiveParameter] string $sessionId): string|false
|
||||
{
|
||||
$data = $this->handler->read($sessionId);
|
||||
if (false === $data = $this->handler->read($sessionId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->marshaller->unmarshall($data);
|
||||
|
||||
+8
-2
@@ -57,9 +57,15 @@ class MemcachedSessionHandler extends AbstractSessionHandler
|
||||
return $this->memcached->quit();
|
||||
}
|
||||
|
||||
protected function doRead(#[\SensitiveParameter] string $sessionId): string
|
||||
protected function doRead(#[\SensitiveParameter] string $sessionId): string|false
|
||||
{
|
||||
return $this->memcached->get($this->prefix.$sessionId) ?: '';
|
||||
$data = $this->memcached->get($this->prefix.$sessionId);
|
||||
|
||||
if (false === $data && \Memcached::RES_NOTFOUND !== $this->memcached->getResultCode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data ?: '';
|
||||
}
|
||||
|
||||
public function updateTimestamp(#[\SensitiveParameter] string $sessionId, string $data): bool
|
||||
|
||||
+15
-2
@@ -38,7 +38,20 @@ class MigratingSessionHandler implements \SessionHandlerInterface, \SessionUpdat
|
||||
$this->writeOnlyHandler = $writeOnlyHandler;
|
||||
}
|
||||
|
||||
public function create_sid(): string
|
||||
public function __serialize(): array
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function create_sid()
|
||||
{
|
||||
return session_create_id() ?: throw new \RuntimeException('Unable to create a session ID.');
|
||||
}
|
||||
@@ -75,7 +88,7 @@ class MigratingSessionHandler implements \SessionHandlerInterface, \SessionUpdat
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function read(#[\SensitiveParameter] string $sessionId): string
|
||||
public function read(#[\SensitiveParameter] string $sessionId): string|false
|
||||
{
|
||||
// No reading from new handler until switch-over
|
||||
return $this->currentHandler->read($sessionId);
|
||||
|
||||
+9
-4
@@ -187,9 +187,9 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
/**
|
||||
* Adds the Table to the Schema if it doesn't exist.
|
||||
*
|
||||
* @param-immediately-invoked-callable $isSameDatabase
|
||||
* @return Schema The (possibly new) schema with the table added
|
||||
*/
|
||||
public function configureSchema(Schema $schema, ?\Closure $isSameDatabase = null): Schema
|
||||
public function configureSchema(Schema $schema, ?\Closure $isSameDatabase = null)
|
||||
{
|
||||
if ($schema->hasTable($this->table) || ($isSameDatabase && !$isSameDatabase($this->getConnection()->exec(...)))) {
|
||||
return $schema;
|
||||
@@ -296,7 +296,12 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
throw new \DomainException(\sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
|
||||
}
|
||||
|
||||
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted($this->idCol))], true));
|
||||
if (class_exists(PrimaryKeyConstraint::class)) {
|
||||
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted($this->idCol))], true));
|
||||
} else {
|
||||
$table->setPrimaryKey([$this->idCol]);
|
||||
}
|
||||
|
||||
$table->addIndex([$this->lifetimeCol], $this->lifetimeCol.'_idx');
|
||||
}
|
||||
|
||||
@@ -361,7 +366,7 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
return parent::open($savePath, $sessionName);
|
||||
}
|
||||
|
||||
public function read(#[\SensitiveParameter] string $sessionId): string
|
||||
public function read(#[\SensitiveParameter] string $sessionId): string|false
|
||||
{
|
||||
try {
|
||||
return parent::read($sessionId);
|
||||
|
||||
+4
-2
@@ -51,9 +51,11 @@ class RedisSessionHandler extends AbstractSessionHandler
|
||||
$this->ttl = $options['ttl'] ?? null;
|
||||
}
|
||||
|
||||
protected function doRead(#[\SensitiveParameter] string $sessionId): string
|
||||
protected function doRead(#[\SensitiveParameter] string $sessionId): string|false
|
||||
{
|
||||
return $this->redis->get($this->prefix.$sessionId) ?: '';
|
||||
$data = $this->redis->get($this->prefix.$sessionId);
|
||||
|
||||
return $data instanceof ErrorInterface ? false : ($data ?: '');
|
||||
}
|
||||
|
||||
protected function doWrite(#[\SensitiveParameter] string $sessionId, string $data): bool
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class StrictSessionHandler extends AbstractSessionHandler
|
||||
return $this->handler->open($savePath, $sessionName);
|
||||
}
|
||||
|
||||
protected function doRead(#[\SensitiveParameter] string $sessionId): string
|
||||
protected function doRead(#[\SensitiveParameter] string $sessionId): string|false
|
||||
{
|
||||
return $this->handler->read($sessionId);
|
||||
}
|
||||
|
||||
+22
-3
@@ -62,9 +62,16 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* gc_probability, "1"
|
||||
* lazy_write, "1"
|
||||
* name, "PHPSESSID"
|
||||
* referer_check, "" (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
* serialize_handler, "php"
|
||||
* use_strict_mode, "1"
|
||||
* use_cookies, "1"
|
||||
* use_only_cookies, "1" (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
* use_trans_sid, "0" (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
* sid_length, "32" (@deprecated since Symfony 7.2, to be removed in 8.0)
|
||||
* sid_bits_per_character, "5" (@deprecated since Symfony 7.2, to be removed in 8.0)
|
||||
* trans_sid_hosts, $_SERVER['HTTP_HOST'] (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
* trans_sid_tags, "a=href,area=href,frame=src,form=" (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
*/
|
||||
public function __construct(array $options = [], AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null)
|
||||
{
|
||||
@@ -115,12 +122,16 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
*
|
||||
* ---------- Part 1
|
||||
*
|
||||
* The part `[a-zA-Z0-9,-]` corresponds to the character range when PHP's `session.sid_bits_per_character` is set to 6.
|
||||
* The part `[a-zA-Z0-9,-]` is related to the PHP ini directive `session.sid_bits_per_character` defined as 6.
|
||||
* See https://php.net/session.configuration#ini.session.sid-bits-per-character
|
||||
* Allowed values are integers such as:
|
||||
* - 4 for range `a-f0-9`
|
||||
* - 5 for range `a-v0-9` (@deprecated since Symfony 7.2, it will default to 4 and the option will be ignored in Symfony 8.0)
|
||||
* - 6 for range `a-zA-Z0-9,-` (@deprecated since Symfony 7.2, it will default to 4 and the option will be ignored in Symfony 8.0)
|
||||
*
|
||||
* ---------- Part 2
|
||||
*
|
||||
* The part `{22,250}` defines the acceptable length range for session IDs.
|
||||
* The part `{22,250}` is related to the PHP ini directive `session.sid_length`.
|
||||
* See https://php.net/session.configuration#ini.session.sid-length
|
||||
* Allowed values are integers between 22 and 256, but we use 250 for the max.
|
||||
*
|
||||
@@ -128,6 +139,8 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* - The length of Windows and Linux filenames is limited to 255 bytes. Then the max must not exceed 255.
|
||||
* - The session filename prefix is `sess_`, a 5 bytes string. Then the max must not exceed 255 - 5 = 250.
|
||||
*
|
||||
* This is @deprecated since Symfony 7.2, the sid length will default to 32 and the option will be ignored in Symfony 8.0.
|
||||
*
|
||||
* ---------- Conclusion
|
||||
*
|
||||
* The parts 1 and 2 prevent the warning below:
|
||||
@@ -310,11 +323,17 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
'cache_expire', 'cache_limiter', 'cookie_domain', 'cookie_httponly',
|
||||
'cookie_lifetime', 'cookie_path', 'cookie_secure', 'cookie_samesite',
|
||||
'gc_divisor', 'gc_maxlifetime', 'gc_probability',
|
||||
'lazy_write', 'name',
|
||||
'lazy_write', 'name', 'referer_check',
|
||||
'serialize_handler', 'use_strict_mode', 'use_cookies',
|
||||
'use_only_cookies', 'use_trans_sid',
|
||||
'sid_length', 'sid_bits_per_character', 'trans_sid_hosts', 'trans_sid_tags',
|
||||
]);
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
if (\in_array($key, ['referer_check', 'use_only_cookies', 'use_trans_sid', 'trans_sid_hosts', 'trans_sid_tags', 'sid_length', 'sid_bits_per_character'], true)) {
|
||||
trigger_deprecation('symfony/http-foundation', '7.2', 'NativeSessionStorage\'s "%s" option is deprecated and will be ignored in Symfony 8.0.', $key);
|
||||
}
|
||||
|
||||
if (isset($validOptions[$key])) {
|
||||
if ('cookie_secure' === $key && 'auto' === $value) {
|
||||
continue;
|
||||
|
||||
+4
-1
@@ -62,7 +62,10 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
|
||||
return $this->handler->gc($maxlifetime);
|
||||
}
|
||||
|
||||
public function create_sid(): string
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function create_sid()
|
||||
{
|
||||
return session_create_id() ?: throw new \RuntimeException('Unable to create a session ID.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user