-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[11.x] Prevent unintended serialization and compression #54337
[11.x] Prevent unintended serialization and compression #54337
Conversation
6b30df9
to
f4ecf92
Compare
src/Illuminate/Cache/RedisStore.php
Outdated
*/ | ||
protected function storePlainValue($value): bool | ||
{ | ||
return is_numeric($value) && ! in_array($value, [INF, -INF]) && ! is_nan($value); |
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.
Please wait with this solution. I need to verify with the phpredis maintainer. You could break the cache component once again when serialization/compression is enabled.
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.
We can merge this one
Is it possible to contribute here or should I open a new pull request on my own? |
@TheLevti what needs to be changed? |
I just confirmed with the maintainers of phpredis, that this behaviour is by design. A value stored with serialization/compression, can not be incremented/decremented. So for us, inside the rate limit component when we set the initial counter value, we need to skip serialization and store the value as is (when serialization/compression is enabled). Solution is basically similar to what is done here. Instead of globally skipping the pack call for any Cache component usage, we should do this only when used by the RateLimiter component. (for setting the initial counter value) |
@TheLevti is there a big issue with just doing it globally in the cache component? |
Also checked that. Theoretically possible even though it would be not correct. We can come up with a smarter solution later and use this proposal for now. |
<?php
$r = new Redis;
$r->connect('localhost', 6379);
shell_exec('redis-cli set foo not-valid-serialization');
$r->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
var_dump($r->get('foo')); ❯ php /tmp/fallback.php
string(23) "not-valid-serialization" So it will work |
I have used the following test in /**
* @param string $driver
*/
#[DataProvider('redisDriverProvider')]
public function testRedisCacheRateLimiter($driver)
{
$store = new RedisStore($this->redis[$driver]);
$repository = new Repository($store);
$rateLimiter = new RateLimiter($repository);
$this->assertFalse($rateLimiter->tooManyAttempts('key', 1));
$this->assertEquals(1, $rateLimiter->hit('key', 60));
$this->assertTrue($rateLimiter->tooManyAttempts('key', 1));
} |
This pull request fixes an issue when using serialization and compression combined with the increment function, introduced in #54221.
This is something used by the RateLimiter and causes it to fail since the v11.39.0.
This PR is intended to fix #54307.