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

chore: Add validation to prevent message flooding #9254

Merged
merged 5 commits into from
Apr 18, 2024

Conversation

sojan-official
Copy link
Member

  • Add a validation to limit messages created per minute to avoid message flooding cases.

lib/limits.rb Outdated Show resolved Hide resolved
Co-authored-by: Pranav <pranav@chatwoot.com>
return if conversation.blank?

# there are cases where automations can result in message loops, we need to prevent such cases.
errors.add(:base, 'Too many messages') if conversation.messages.where('created_at >= ?',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Extend the limit to 200 per minute.
  • Add Rails.logger for the error.
  • Create an alert on NewRelic for this error.

@sojan-official sojan-official temporarily deployed to chatwoot-pr-9254 April 18, 2024 04:45 Inactive

# there are cases where automations can result in message loops, we need to prevent such cases.
if conversation.messages.where('created_at >= ?', 1.minute.ago).count >= Limits.conversation_message_per_minute_limit
Rails.logger.error "Too many message: Account Id - #{account_id} : Conversation id - #{conversation_id}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vishnu-narayanan Could you add a trigger for this one ?

@sojan-official sojan-official merged commit 15638e9 into develop Apr 18, 2024
15 of 16 checks passed
@sojan-official sojan-official deleted the chore/validation-for-message-loops branch April 18, 2024 07:15
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants