Validate Identity email address

using the "standard" email regexp URI::MailTo::EMAIL_REGEXP. The form
field will validate this in the browser, but if bots are creating
identities, they can put whatever they want in here. So let's add some
protection against that.

The HtmlHelper regex was renamed here to avoid confusing Brakeman,
which does imprecise constant lookup and was confusing the two
constants, one of which uses `\A` and `\z` and the other does
not (intentionally).

ref: https://app.fizzy.do/5986089/cards/3276
This commit is contained in:
Mike Dalessio
2025-12-04 13:24:55 -05:00
parent 03e4f86b7a
commit 00eee29837
4 changed files with 32 additions and 2 deletions
+1
View File
@@ -10,6 +10,7 @@ class Identity < ApplicationRecord
before_destroy :deactivate_users
validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP }
normalizes :email_address, with: ->(value) { value.strip.downcase.presence }
def send_magic_link(**attributes)