mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
SECURITY: Limit chat message char length (#19207)
Only allow maximum of 6000 characters for chat messages when they are created or edited. A hidden setting can control this limit, 6000 is the default. There is also a migration here to truncate any existing messages to 6000 characters if the message is already over that and if the chat_messages table exists. We also set cooked_version to NULL for those messages so we can identify them for rebake.
This commit is contained in:
@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TruncateChatMessagesOverMaxLength < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
if table_exists?(:chat_messages)
|
||||
# 6000 is the default of the chat_maximum_message_length
|
||||
# site setting, its safe to do this because this will be
|
||||
# run the first time the setting is introduced.
|
||||
execute <<~SQL
|
||||
UPDATE chat_messages
|
||||
SET message = LEFT(message, 6000), cooked_version = NULL
|
||||
WHERE LENGTH(message) > 6000
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user