Skip to content

Commit

Permalink
Disallow too long passwords for users.
Browse files Browse the repository at this point in the history
Devise default hashing algorithm Bcrypt uses only 72 bytes of
data in order to create a password hash. Rest of it is truncated,
leading to some potential serious security vulnerabilities.
  • Loading branch information
marcel-strzalka committed Oct 5, 2022
1 parent 82449db commit 298e834
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# frozen_string_literal: true

class User < ApplicationRecord
BCRYPT_BYTESIZE_LIMIT = 72

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable

has_many :reservations, dependent: :destroy

enum :role, %i[customer manager]

validate do
errors.add(:base, 'Password is too long') if password.bytesize > BCRYPT_BYTESIZE_LIMIT
end
end

0 comments on commit 298e834

Please sign in to comment.