From 7a7cb78f821b9a95956593a0ed61e8676452bf9a Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sat, 26 Dec 2020 07:11:10 +0000 Subject: [PATCH] Check bool environment variables are "1" or "true" --- src/util/util.cr | 6 ++++++ src/util/web.cr | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util/util.cr b/src/util/util.cr index 90197202..3fc1b2d5 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -61,3 +61,9 @@ class String self.chars.all? { |c| c.alphanumeric? || c == '_' } end end + +def env_is_true?(key : String) : Bool + val = ENV[key.upcase]? || ENV[key.downcase]? + return false unless val + val.downcase.in? "1", "true" +end diff --git a/src/util/web.cr b/src/util/web.cr index 186beb7c..c384099f 100644 --- a/src/util/web.cr +++ b/src/util/web.cr @@ -86,9 +86,7 @@ module HTTP class Client private def self.exec(uri : URI, tls : TLSContext = nil) previous_def uri, tls do |client, path| - disable_ssl_verification = ENV["DISABLE_SSL_VERIFICATION"]? || - ENV["disable_ssl_verification"]? - if disable_ssl_verification && client.tls? + if client.tls? && env_is_true? "DISABLE_SSL_VERIFICATION" Logger.debug "Disabling SSL verification" client.tls.verify_mode = OpenSSL::SSL::VerifyMode::NONE end