From 1a27f42140b5966a11b3591112c48232c3227685 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 29 Jun 2016 21:18:09 -0400 Subject: [PATCH] Fix crash in warden hook It seems that in some cases `action_dispatch.cookies` is not set in the environment during the `after_authentication` hook. --- .../hooks/two_factor_authenticatable.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/two_factor_authentication/hooks/two_factor_authenticatable.rb b/lib/two_factor_authentication/hooks/two_factor_authenticatable.rb index 81ea5bc..3808755 100644 --- a/lib/two_factor_authentication/hooks/two_factor_authenticatable.rb +++ b/lib/two_factor_authentication/hooks/two_factor_authenticatable.rb @@ -1,11 +1,9 @@ Warden::Manager.after_authentication do |user, auth, options| reset_otp_state_for(user) - expected_cookie_value = "#{user.class}-#{user.id}" - actual_cookie_value = auth.env["action_dispatch.cookies"].signed[TwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME] - if actual_cookie_value.nil? - bypass_by_cookie = false - else + if auth.env["action_dispatch.cookies"] + expected_cookie_value = "#{user.class}-#{user.id}" + actual_cookie_value = auth.env["action_dispatch.cookies"].signed[TwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME] bypass_by_cookie = actual_cookie_value == expected_cookie_value end