From 29a5837c29620e33857d7a5afce01384e3f8e41a Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 14 Aug 2022 13:18:07 +0200 Subject: [PATCH] Validate length of user's name attribute This attribute is a text column, so it could be very long even in a MySQL database. Limit it to a generous length. --- publify_core/app/models/user.rb | 1 + publify_core/spec/models/user_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/publify_core/app/models/user.rb b/publify_core/app/models/user.rb index c9555abc18..226183e3c9 100644 --- a/publify_core/app/models/user.rb +++ b/publify_core/app/models/user.rb @@ -22,6 +22,7 @@ class User < ApplicationRecord validates :email, :login, presence: true validates :login, length: { in: 3..40 } validates_default_string_length :email, :text_filter_name + validates :name, length: { maximum: 2048 } belongs_to :resource, optional: true has_many :notifications, foreign_key: "notify_user_id" diff --git a/publify_core/spec/models/user_spec.rb b/publify_core/spec/models/user_spec.rb index a8457ef283..54ea166556 100644 --- a/publify_core/spec/models/user_spec.rb +++ b/publify_core/spec/models/user_spec.rb @@ -49,6 +49,10 @@ expect(user).to validate_length_of(:email).is_at_most(255) end + it "requires name to not be too long" do + expect(user).to validate_length_of(:name).is_at_most(2048) + end + it "requires first name to not be too long" do expect(user).to validate_length_of(:firstname).is_at_most(256) end