SECURITY: Limit ThemeField value length to prevent DoS (#22087)

Co-authored-by: Daniel Waterworth <me@danielwaterworth.com>
This commit is contained in:
Blake Erickson
2023-06-13 11:07:47 -06:00
committed by GitHub
parent e576fdbe3a
commit 56b74e6042
3 changed files with 46 additions and 1 deletions

View File

@@ -5,6 +5,8 @@ class ThemeField < ActiveRecord::Base
has_one :javascript_cache, dependent: :destroy
has_one :upload_reference, as: :target, dependent: :destroy
validates :value, { length: { maximum: 1024**2 } }
after_save do
if self.type_id == ThemeField.types[:theme_upload_var] && saved_change_to_upload_id?
UploadReference.ensure_exist!(upload_ids: [self.upload_id], target: self)