From 5dfe86addf75b96e69032791508daeee82aee01c Mon Sep 17 00:00:00 2001 From: Alex Nizamov Date: Sun, 5 Oct 2025 04:33:19 +0500 Subject: [PATCH] Fix Sidekiq UI auth --- config.ru | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/config.ru b/config.ru index 1f1db906..cf47236d 100644 --- a/config.ru +++ b/config.ru @@ -20,17 +20,22 @@ use Airbrake::Rack::Middleware if ENV['AIRBRAKE_PROJECT_ID'].present? map '/sidekiq' do unless MR.env == 'development' use Rack::Auth::Basic, 'Protected Area' do |username, password| - username_matches = Rack::Utils.secure_compare( - Digest::SHA256.hexdigest(username), - Digest::SHA256.hexdigest(ENV.fetch('SIDEKIQ_USERNAME', nil)) - ) - - password_matches = Rack::Utils.secure_compare( - Digest::SHA256.hexdigest(password), - Digest::SHA256.hexdigest(ENV.fetch('SIDEKIQ_PASSWORD', nil)) - ) - - username_matches && password_matches + if ENV.key?('SIDEKIQ_USERNAME') && ENV.key?('SIDEKIQ_PASSWORD') + username_matches = Rack::Utils.secure_compare( + Digest::SHA256.hexdigest(username), + Digest::SHA256.hexdigest(ENV.fetch('SIDEKIQ_USERNAME', nil)) + ) + + password_matches = Rack::Utils.secure_compare( + Digest::SHA256.hexdigest(password), + Digest::SHA256.hexdigest(ENV.fetch('SIDEKIQ_PASSWORD', nil)) + ) + + username_matches && password_matches + else + MR.logger.warn("SIDEKIQ_USERNAME or SIDEKIQ_PASSWORD is missing") + false + end end end