From d7c0507e33496942ba70c97110bbe21de85f33c3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Feb 2025 17:35:12 -0800 Subject: [PATCH 1/4] chore(deps): Bump net-imap from 0.4.17 to 0.4.19 (#10871) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [net-imap](https://github.com/ruby/net-imap) from 0.4.17 to 0.4.19.
Release notes

Sourced from net-imap's releases.

v0.4.19

What's Changed

🔒 Security Fix

Fixes CVE-2025-25186 (GHSA-7fc5-f82f-cx69): A malicious server can exhaust client memory by sending APPENDUID or COPYUID responses with very large uid-set ranges. Net::IMAP::UIDPlusData expands these ranges into arrays of integers.

Fix with minor API changes

Set config.parser_use_deprecated_uidplus_data to false to replace UIDPlusData with AppendUIDData and CopyUIDData. These classes store their UIDs as Net::IMAP::SequenceSet objects (not expanded into arrays of integers). Code that does not handle APPENDUID or COPYUID responses should not see any difference. Code that does handle these responses may need to be updated.

For v0.3.8, this option is not available For v0.4.19, the default value is true. For v0.5.6, the default value is :up_to_max_size. For v0.6.0, the only allowed value will be false (UIDPlusData will be removed from v0.6).

Mitigate with backward compatible API

Adjust config.parser_max_deprecated_uidplus_data_size to limit the maximum UIDPlusData UID set size. When config.parser_use_deprecated_uidplus_data == true, larger sets will crash. When config.parser_use_deprecated_uidplus_data == :up_to_max_size, larger sets will use AppendUIDData or CopyUIDData.

For v0.3,8, this limit is hard-coded to 10,000. For v0.4.19, this limit defaults to 1000. For v0.5.6, this limit defaults to 100. For v0.6.0, the only allowed value will be 0 (UIDPlusData will be removed from v0.6).

Please Note: unhandled responses

If the client does not add response handlers to prune unhandled responses, a malicious server can still eventually exhaust all client memory, by repeatedly sending malicious responses. However, net-imap has always retained unhandled responses, and it has always been necessary for long-lived connections to prune these responses. This is not significantly different from connecting to a trusted server with a long-lived connection. To limit the maximum number of retained responses, a simple handler might look something like the following:

limit = 1000
imap.add_response_handler do |resp|
  next unless resp.respond_to?(:name) && resp.respond_to?(:data)
  name = resp.name
code = resp.data.code&.name if
resp.data.in?(Net::IMAP::ResponseText)
  imap.responses(name) { _1.slice!(0...-limit) }
  imap.responses(code) { _1.slice!(0...-limit) }
end

Added

... (truncated)

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=net-imap&package-manager=bundler&previous-version=0.4.17&new-version=0.4.19)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/chatwoot/chatwoot/network/alerts).
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 45c54bd46..fa45d1e89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -186,7 +186,7 @@ GEM database_cleaner-core (2.0.1) datadog-ci (0.8.3) msgpack - date (3.3.4) + date (3.4.1) ddtrace (1.23.2) datadog-ci (~> 0.8.1) debase-ruby_core_source (= 3.3.1) @@ -487,7 +487,7 @@ GEM uri net-http-persistent (4.0.2) connection_pool (~> 2.2) - net-imap (0.4.17) + net-imap (0.4.19) date net-protocol net-pop (0.1.2) @@ -782,7 +782,7 @@ GEM time_diff (0.3.0) activesupport i18n - timeout (0.4.1) + timeout (0.4.3) trailblazer-option (0.1.2) twilio-ruby (5.77.0) faraday (>= 0.9, < 3.0) From 02000de90523fb43bb9c33699c073e14309fd16f Mon Sep 17 00:00:00 2001 From: Pranav Date: Mon, 10 Feb 2025 19:33:26 -0800 Subject: [PATCH 2/4] chore: Add updated_at attribute to the conversation event (#10873) This PR adds updated_at attribute to the conversation event. --- app/presenters/conversations/event_data_presenter.rb | 3 ++- .../api/v1/conversations/partials/_conversation.json.jbuilder | 1 + spec/models/conversation_spec.rb | 1 + spec/presenters/conversations/event_data_presenter_spec.rb | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/presenters/conversations/event_data_presenter.rb b/app/presenters/conversations/event_data_presenter.rb index 2617721ec..1ba188de8 100644 --- a/app/presenters/conversations/event_data_presenter.rb +++ b/app/presenters/conversations/event_data_presenter.rb @@ -42,7 +42,8 @@ class Conversations::EventDataPresenter < SimpleDelegator contact_last_seen_at: contact_last_seen_at.to_i, last_activity_at: last_activity_at.to_i, timestamp: last_activity_at.to_i, - created_at: created_at.to_i + created_at: created_at.to_i, + updated_at: updated_at.to_i } end end diff --git a/app/views/api/v1/conversations/partials/_conversation.json.jbuilder b/app/views/api/v1/conversations/partials/_conversation.json.jbuilder index a9a580e26..2e6474953 100644 --- a/app/views/api/v1/conversations/partials/_conversation.json.jbuilder +++ b/app/views/api/v1/conversations/partials/_conversation.json.jbuilder @@ -44,6 +44,7 @@ json.muted conversation.muted? json.snoozed_until conversation.snoozed_until json.status conversation.status json.created_at conversation.created_at.to_i +json.updated_at conversation.updated_at.to_i json.timestamp conversation.last_activity_at.to_i json.first_reply_created_at conversation.first_reply_created_at.to_i json.unread_count conversation.unread_incoming_messages.count diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 5813d8c3c..0c8f9de50 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -538,6 +538,7 @@ RSpec.describe Conversation do contact_last_seen_at: conversation.contact_last_seen_at.to_i, agent_last_seen_at: conversation.agent_last_seen_at.to_i, created_at: conversation.created_at.to_i, + updated_at: conversation.updated_at.to_i, waiting_since: conversation.waiting_since.to_i, priority: nil, unread_count: 0 diff --git a/spec/presenters/conversations/event_data_presenter_spec.rb b/spec/presenters/conversations/event_data_presenter_spec.rb index f6a400b96..6f2534efb 100644 --- a/spec/presenters/conversations/event_data_presenter_spec.rb +++ b/spec/presenters/conversations/event_data_presenter_spec.rb @@ -31,6 +31,7 @@ RSpec.describe Conversations::EventDataPresenter do contact_last_seen_at: conversation.contact_last_seen_at.to_i, agent_last_seen_at: conversation.agent_last_seen_at.to_i, created_at: conversation.created_at.to_i, + updated_at: conversation.updated_at.to_i, waiting_since: conversation.waiting_since.to_i, priority: nil, unread_count: 0 From 8faccba052e9ebb0cc33acb5ba2626373866720d Mon Sep 17 00:00:00 2001 From: Pranav Date: Mon, 10 Feb 2025 20:22:11 -0800 Subject: [PATCH 3/4] chore: Update the precision of the updated_at timestamp in conversation model (#10875) Use to_f instead of to_i to preserve the millisecond precision in the UI. --- app/presenters/conversations/event_data_presenter.rb | 2 +- .../api/v1/conversations/partials/_conversation.json.jbuilder | 2 +- spec/models/conversation_spec.rb | 2 +- spec/presenters/conversations/event_data_presenter_spec.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/presenters/conversations/event_data_presenter.rb b/app/presenters/conversations/event_data_presenter.rb index 1ba188de8..2ef69080d 100644 --- a/app/presenters/conversations/event_data_presenter.rb +++ b/app/presenters/conversations/event_data_presenter.rb @@ -43,7 +43,7 @@ class Conversations::EventDataPresenter < SimpleDelegator last_activity_at: last_activity_at.to_i, timestamp: last_activity_at.to_i, created_at: created_at.to_i, - updated_at: updated_at.to_i + updated_at: updated_at.to_f } end end diff --git a/app/views/api/v1/conversations/partials/_conversation.json.jbuilder b/app/views/api/v1/conversations/partials/_conversation.json.jbuilder index 2e6474953..8867ba695 100644 --- a/app/views/api/v1/conversations/partials/_conversation.json.jbuilder +++ b/app/views/api/v1/conversations/partials/_conversation.json.jbuilder @@ -44,7 +44,7 @@ json.muted conversation.muted? json.snoozed_until conversation.snoozed_until json.status conversation.status json.created_at conversation.created_at.to_i -json.updated_at conversation.updated_at.to_i +json.updated_at conversation.updated_at.to_f json.timestamp conversation.last_activity_at.to_i json.first_reply_created_at conversation.first_reply_created_at.to_i json.unread_count conversation.unread_incoming_messages.count diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 0c8f9de50..1938fb204 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -538,7 +538,7 @@ RSpec.describe Conversation do contact_last_seen_at: conversation.contact_last_seen_at.to_i, agent_last_seen_at: conversation.agent_last_seen_at.to_i, created_at: conversation.created_at.to_i, - updated_at: conversation.updated_at.to_i, + updated_at: conversation.updated_at.to_f, waiting_since: conversation.waiting_since.to_i, priority: nil, unread_count: 0 diff --git a/spec/presenters/conversations/event_data_presenter_spec.rb b/spec/presenters/conversations/event_data_presenter_spec.rb index 6f2534efb..a645caf1d 100644 --- a/spec/presenters/conversations/event_data_presenter_spec.rb +++ b/spec/presenters/conversations/event_data_presenter_spec.rb @@ -31,7 +31,7 @@ RSpec.describe Conversations::EventDataPresenter do contact_last_seen_at: conversation.contact_last_seen_at.to_i, agent_last_seen_at: conversation.agent_last_seen_at.to_i, created_at: conversation.created_at.to_i, - updated_at: conversation.updated_at.to_i, + updated_at: conversation.updated_at.to_f, waiting_since: conversation.waiting_since.to_i, priority: nil, unread_count: 0 From 3c78d25306e0c7e307d8740ad85ff2eae971ce4f Mon Sep 17 00:00:00 2001 From: Pranav Date: Mon, 10 Feb 2025 23:16:15 -0800 Subject: [PATCH 4/4] chore: Reload conversation data in ActionCableBroadcastJob before sending (#10876) During high-traffic periods, events may appear out of order, causing the conversation job to queue outdated data, which can lead to issues in the UI. This update ensures that only the latest available data is sent to the UI. The conversation object is refreshed before sending it to the UI. --- app/jobs/action_cable_broadcast_job.rb | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/jobs/action_cable_broadcast_job.rb b/app/jobs/action_cable_broadcast_job.rb index b1208a97c..ce1230029 100644 --- a/app/jobs/action_cable_broadcast_job.rb +++ b/app/jobs/action_cable_broadcast_job.rb @@ -2,8 +2,34 @@ class ActionCableBroadcastJob < ApplicationJob queue_as :critical def perform(members, event_name, data) + return if members.blank? + + broadcast_data = prepare_broadcast_data(event_name, data) + broadcast_to_members(members, event_name, broadcast_data) + end + + private + + # Ensures that only the latest available data is sent to prevent UI issues + # caused by out-of-order events during high-traffic periods. This prevents + # the conversation job from processing outdated data. + def prepare_broadcast_data(event_name, data) + return data unless event_name == 'conversation.updated' + + account = Account.find(data[:account_id]) + conversation = account.conversations.find_by!(display_id: data[:id]) + conversation.push_event_data.merge(account_id: data[:account_id]) + end + + def broadcast_to_members(members, event_name, broadcast_data) members.each do |member| - ActionCable.server.broadcast(member, { event: event_name, data: data }) + ActionCable.server.broadcast( + member, + { + event: event_name, + data: broadcast_data + } + ) end end end