Skip to content

Commit

Permalink
Fix bug with key length
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianCann committed Jul 1, 2018
1 parent c383f74 commit 90d88bf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ class Page < ActiveRecord::Base

def encryption_key
if password
password + ENV.fetch("SECRET_KEY_BASE")
padded_or_chopped(password)
else
ENV.fetch("SECRET_KEY_BASE")
padded_or_chopped(ENV["SECRET_KEY_BASE"])
end
end

private

def padded_or_chopped(password)
if password.length < 32
" " * (32 - password.length) + password
else
password[0, 32]
end
end

def set_random_url_key
self.url_key = SecureRandom.hex(5) unless self.url_key.present?
end
Expand Down

0 comments on commit 90d88bf

Please sign in to comment.