Merge commit from fork

* Disallow some special characters in e-mail addresses

* Add size limit to email columns
This commit is contained in:
Claire 2026-04-15 15:22:32 +02:00 committed by GitHub
parent 081debc971
commit 5e43c8db56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -99,7 +99,7 @@ class User < ApplicationRecord
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? && !Setting.require_invite_text }
validates :invite_request, presence: true, on: :create, if: :invite_text_required?
validates :email, presence: true, email_address: true
validates :email, presence: true, email_address: true, length: { maximum: 320 }
validates_with UserEmailValidator, if: -> { ENV['EMAIL_DOMAIN_LISTS_APPLY_AFTER_CONFIRMATION'] == 'true' || !confirmed? }
validates_with EmailMxValidator, if: :validate_email_dns?

View File

@ -11,8 +11,14 @@ class EmailAddressValidator < ActiveModel::EachValidator
value = value.strip
address = Mail::Address.new(value)
record.errors.add(attribute, :invalid) if address.address != value
record.errors.add(attribute, :invalid) if address.address != value || contains_disallowed_characters?(value)
rescue Mail::Field::FieldError
record.errors.add(attribute, :invalid)
end
private
def contains_disallowed_characters?(value)
value.include?('%') || value.include?(',') || value.include?('"')
end
end