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
@@ -34,6 +34,18 @@ class SignupsControllerTest < ActionDispatch::IntegrationTest
end
end
test "create with email address containing blanks" do
untenanted do
assert_no_difference -> { Identity.count } do
assert_no_difference -> { MagicLink.count } do
post signup_path, params: { signup: { email_address: "sam smith@example.com" } }
end
end
assert_response :unprocessable_entity
end
end
test "create for an authenticated user" do
identity = identities(:kevin)
sign_in_as identity