From 7dd4c7620b3baa7597532d8176df0b3b93c52db1 Mon Sep 17 00:00:00 2001 From: Adrian Cann Date: Sat, 30 Jun 2018 19:21:38 -0400 Subject: [PATCH] Fix bug with key length https://github.com/attr-encrypted/encryptor/issues/26 ***Temporary*** * This is a temporary fix to make this work and get all the CI tests working. Not the most secure solution --- app/models/page.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index e612d5f..ebe69a0 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -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