fix: Erase null bytes from incoming Twilio messages (#7901)
We've had some messages come in from a few different phone numbers that had null bytes in them. I don't know how this happens. They don't seem to be malicious. They currently cause the Postgres gem to raise an error when Chatwoot attempts to save the message body to the database: ArgumentError (string contains null byte) Related Rails GitHub issue: rails/rails#26891
This commit is contained in:
@@ -9,7 +9,7 @@ class Twilio::IncomingMessageService
|
||||
set_contact
|
||||
set_conversation
|
||||
@message = @conversation.messages.create!(
|
||||
content: params[:Body],
|
||||
content: message_body,
|
||||
account_id: @inbox.account_id,
|
||||
inbox_id: @inbox.id,
|
||||
message_type: :incoming,
|
||||
@@ -46,6 +46,10 @@ class Twilio::IncomingMessageService
|
||||
TelephoneNumber.parse(phone_number).international_number
|
||||
end
|
||||
|
||||
def message_body
|
||||
params[:Body].delete("\u0000")
|
||||
end
|
||||
|
||||
def set_contact
|
||||
contact_inbox = ::ContactInboxWithContactBuilder.new(
|
||||
source_id: params[:From],
|
||||
|
||||
Reference in New Issue
Block a user