mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
SECURITY: Check the length of raw post body (#19733)
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
committed by
GitHub
parent
692329896a
commit
bf6b08670a
@@ -2,12 +2,16 @@
|
||||
|
||||
class StrippedLengthValidator < ActiveModel::EachValidator
|
||||
def self.validate(record, attribute, value, range)
|
||||
if !value.nil?
|
||||
value = get_sanitized_value(value)
|
||||
record.errors.add attribute, (I18n.t('errors.messages.too_short', count: range.begin)) if value.length < range.begin
|
||||
record.errors.add attribute, (I18n.t('errors.messages.too_long_validation', max: range.end, length: value.length)) if value.length > range.end
|
||||
if value.nil?
|
||||
record.errors.add attribute, I18n.t('errors.messages.blank')
|
||||
elsif value.length > range.end
|
||||
record.errors.add attribute, I18n.t('errors.messages.too_long_validation', max: range.end, length: value.length)
|
||||
else
|
||||
record.errors.add attribute, (I18n.t('errors.messages.blank'))
|
||||
value = get_sanitized_value(value)
|
||||
|
||||
if value.length < range.begin
|
||||
record.errors.add attribute, I18n.t('errors.messages.too_short', count: range.begin)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user