-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] [Throttling] Hide username and client ip in logs #51434
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,11 +28,20 @@ final class DefaultLoginRateLimiter extends AbstractRequestRateLimiter | |
{ | ||
private RateLimiterFactory $globalFactory; | ||
private RateLimiterFactory $localFactory; | ||
private string $secret; | ||
|
||
public function __construct(RateLimiterFactory $globalFactory, RateLimiterFactory $localFactory) | ||
/** | ||
* @param non-empty-string $secret A secret to use for hashing the IP address and username | ||
*/ | ||
public function __construct(RateLimiterFactory $globalFactory, RateLimiterFactory $localFactory, #[\SensitiveParameter] string $secret = '') | ||
{ | ||
if ('' === $secret) { | ||
trigger_deprecation('symfony/security-http', '6.4', 'Calling "%s()" with an empty secret is deprecated. A non-empty secret will be mandatory in version 7.0.', __METHOD__); | ||
// throw new \Symfony\Component\Security\Core\Exception\InvalidArgumentException('A non-empty secret is required.'); | ||
} | ||
$this->globalFactory = $globalFactory; | ||
$this->localFactory = $localFactory; | ||
$this->secret = $secret; | ||
} | ||
|
||
protected function getLimiters(Request $request): array | ||
|
@@ -41,8 +50,13 @@ protected function getLimiters(Request $request): array | |
$username = preg_match('//u', $username) ? mb_strtolower($username, 'UTF-8') : strtolower($username); | ||
|
||
return [ | ||
$this->globalFactory->create($request->getClientIp()), | ||
$this->localFactory->create($username.'-'.$request->getClientIp()), | ||
$this->globalFactory->create($this->hash($request->getClientIp())), | ||
$this->localFactory->create($this->hash($username.'-'.$request->getClientIp())), | ||
]; | ||
} | ||
|
||
private function hash(string $data): string | ||
{ | ||
return strtr(substr(base64_encode(hash_hmac('sha256', $data, $this->secret, true)), 0, 8), '/+', '._'); | ||
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 came here to check as I was worried I'd have to complain about a massive cache size increase, but I'm happy to see that it was taken into account and this will actually probably even reduce the cache storage requirements. Thanks! 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. Honestly, I fell into the trap 😅🤦♂️. But there are people here who are very quick-witted and who paid attention to that 😊. #bestcommunityever 👌 |
||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.