Fix rate limit and make it more strict (1 message in 5 minutes)
This commit is contained in:
@@ -85,15 +85,16 @@ class Comment extends Component
|
||||
|
||||
$user = auth()->user();
|
||||
$rateLimitKey = "send-comment:{$user->id}";
|
||||
$rateLimitMinutes = 60 * 5; // 5 minutes
|
||||
|
||||
if (RateLimiter::tooManyAttempts($rateLimitKey, 5)) {
|
||||
if (RateLimiter::tooManyAttempts($rateLimitKey, 1)) {
|
||||
$seconds = RateLimiter::availableIn($rateLimitKey);
|
||||
|
||||
$this->addError('replyState.body', "Too many comments. Try again in {$seconds} seconds.");
|
||||
return;
|
||||
}
|
||||
|
||||
RateLimiter::hit($rateLimitKey, 60);
|
||||
RateLimiter::hit($rateLimitKey, $rateLimitMinutes);
|
||||
|
||||
$this->validate([
|
||||
'replyState.body' => 'required'
|
||||
|
||||
@@ -31,20 +31,18 @@ class Comments extends Component
|
||||
'newCommentState.body' => 'required'
|
||||
]);
|
||||
|
||||
$this->addError('newCommentState.body', "Too many comments. Try again in 1 seconds.");
|
||||
return;
|
||||
|
||||
$user = auth()->user();
|
||||
$rateLimitKey = "send-comment:{$user->id}";
|
||||
$rateLimitMinutes = 60 * 5; // 5 minutes
|
||||
|
||||
if (RateLimiter::tooManyAttempts($rateLimitKey, 5)) {
|
||||
if (RateLimiter::tooManyAttempts($rateLimitKey, 1)) {
|
||||
$seconds = RateLimiter::availableIn($rateLimitKey);
|
||||
|
||||
$this->addError('newCommentState.body', "Too many comments. Try again in {$seconds} seconds.");
|
||||
return;
|
||||
}
|
||||
|
||||
RateLimiter::hit($rateLimitKey, 60);
|
||||
RateLimiter::hit($rateLimitKey, $rateLimitMinutes);
|
||||
|
||||
$comment = $this->model->comments()->make($this->newCommentState);
|
||||
$comment->user()->associate($user);
|
||||
|
||||
Reference in New Issue
Block a user