Skip to content
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

[9.x] Prevent double sanitized key in RateLimiter@tooManyAttempts #42462

Merged
merged 2 commits into from
May 23, 2022
Merged

[9.x] Prevent double sanitized key in RateLimiter@tooManyAttempts #42462

merged 2 commits into from
May 23, 2022

Conversation

HanakJakub
Copy link
Contributor

Issue with RateLimiter with key containing '.

// Key with apostrophe
$key = "john'doe";

$rateLimiter->hit($key);

$rateLimiter->tooManyAttempts($key, 1); // false 

Calling $rateLimiter->hit($key) with key like john'doe. Will use $this->cleanRateLimiterKey($key) inside RateLimiter, which is john'doe.

Then $rateLimiter->tooManyAttempts($key, 1) was calling $key = $this->cleanRateLimiterKey($key) and then passing cleaned key to the $rateLimiter->attempts($key) which cleaned the key again and returned johna#039;doe.

So it was changing the key from john'doe to johna#039;doe. & to a

@taylorotwell
Copy link
Member

Tests seem to be failing on PHP 8?

@taylorotwell taylorotwell marked this pull request as draft May 20, 2022 14:07
@taylorotwell
Copy link
Member

Please mark as ready for review once the tests as passing.

@HanakJakub
Copy link
Contributor Author

Issue was probably only in PHP8.1. htmlentities function default of flags parameter was changed and single quotes are now processed too.
https://php.watch/versions/8.1/html-entity-default-value-changes

- htmlentities($string, ENT_COMPAT);
+ htmlentities($string, ENT_QUOTES | ENT_SUBSTITUTE);

@HanakJakub HanakJakub marked this pull request as ready for review May 20, 2022 20:21
@taylorotwell taylorotwell merged commit 127a9ca into laravel:9.x May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants