More Resilient Parsing of Booleans (#1840)

This patch makes parsing booleans from configuration settings more
resilient to ensure no accidental errors occur e.g. due to the use of
upper or lowercase letters.

Example: Without this patch, the following configuration would disable
Greenlight accounts which is quite unexpected behavior from a users
perspective:

    ALLOW_GREENLIGHT_ACCOUNTS=True

Co-authored-by: Ahmad Farhat <ahmad.af.farhat@gmail.com>
This commit is contained in:
Lars Kiesow 2021-02-28 18:43:57 +01:00 committed by GitHub
parent 3eaa61a463
commit c113b5e456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -33,6 +33,11 @@ module Greenlight
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded.
def parse_bool(val, default = false)
val = ActiveModel::Type::Boolean.new.cast(val)
val.nil? ? default : val
end
# Use custom error routes. # Use custom error routes.
config.exceptions_app = routes config.exceptions_app = routes
@ -87,16 +92,16 @@ module Greenlight
config.smtp_sender = ENV['SMTP_SENDER'] || "notifications@example.com" config.smtp_sender = ENV['SMTP_SENDER'] || "notifications@example.com"
# Determine if GreenLight should enable email verification # Determine if GreenLight should enable email verification
config.enable_email_verification = (ENV['ALLOW_MAIL_NOTIFICATIONS'] == "true") config.enable_email_verification = parse_bool(ENV['ALLOW_MAIL_NOTIFICATIONS'])
# Determine if GreenLight should allow non-omniauth signup/login. # Determine if GreenLight should allow non-omniauth signup/login.
config.allow_user_signup = (ENV['ALLOW_GREENLIGHT_ACCOUNTS'] == "true") config.allow_user_signup = parse_bool(ENV['ALLOW_GREENLIGHT_ACCOUNTS'])
# Configure custom banner message. # Configure custom banner message.
config.banner_message = ENV['BANNER_MESSAGE'] config.banner_message = ENV['BANNER_MESSAGE']
# Enable/disable recording thumbnails. # Enable/disable recording thumbnails.
config.recording_thumbnails = (ENV['RECORDING_THUMBNAILS'] != "false") config.recording_thumbnails = parse_bool(ENV['RECORDING_THUMBNAILS'], true)
# Configure which settings are available to user on room creation/edit after creation # Configure which settings are available to user on room creation/edit after creation
config.room_features = ENV['ROOM_FEATURES'] || "" config.room_features = ENV['ROOM_FEATURES'] || ""
@ -111,7 +116,7 @@ module Greenlight
config.recaptcha_enabled = ENV['RECAPTCHA_SITE_KEY'].present? && ENV['RECAPTCHA_SECRET_KEY'].present? config.recaptcha_enabled = ENV['RECAPTCHA_SITE_KEY'].present? && ENV['RECAPTCHA_SECRET_KEY'].present?
# Show/hide "Add to Google Calendar" button in the room page # Show/hide "Add to Google Calendar" button in the room page
config.enable_google_calendar_button = (ENV['ENABLE_GOOGLE_CALENDAR_BUTTON'] == "true") config.enable_google_calendar_button = parse_bool(ENV['ENABLE_GOOGLE_CALENDAR_BUTTON'])
# Enum containing the different possible registration methods # Enum containing the different possible registration methods
config.registration_methods = { open: "0", invite: "1", approval: "2" } config.registration_methods = { open: "0", invite: "1", approval: "2" }
@ -119,11 +124,11 @@ module Greenlight
config.google_analytics = ENV["GOOGLE_ANALYTICS_TRACKING_ID"].present? config.google_analytics = ENV["GOOGLE_ANALYTICS_TRACKING_ID"].present?
# Will always be true unless explicitly set to false # Will always be true unless explicitly set to false
config.enable_cache = ENV["ENABLE_CACHED_PROVIDER"] != "false" config.enable_cache = parse_bool(ENV["ENABLE_CACHED_PROVIDER"], true)
# MAINTENANCE # MAINTENANCE
config.maintenance_window = ENV["MAINTENANCE_WINDOW"] config.maintenance_window = ENV["MAINTENANCE_WINDOW"]
config.maintenance_mode = ENV["MAINTENANCE_MODE"] == "true" config.maintenance_mode = parse_bool(ENV["MAINTENANCE_MODE"])
config.report_issue_url = ENV["REPORT_ISSUE_URL"] config.report_issue_url = ENV["REPORT_ISSUE_URL"]
config.help_url = ENV["HELP_URL"].nil? ? "https://docs.bigbluebutton.org/greenlight/gl-overview.html" : ENV["HELP_URL"] config.help_url = ENV["HELP_URL"].nil? ? "https://docs.bigbluebutton.org/greenlight/gl-overview.html" : ENV["HELP_URL"]