@@ -49,12 +49,17 @@ def auto_source_enabled?
4949
5050 def set_development_key
5151 ENV [ 'HTML2RSS_SECRET_KEY' ] = 'development-default-key-not-for-production'
52- puts '⚠️ WARNING: Using default secret key for development/testing only!'
53- puts ' Set HTML2RSS_SECRET_KEY environment variable for production use.'
52+ log_development_default_secret_key_warning
53+ warn_lines (
54+ 'WARNING: Using default secret key for development/testing only!' ,
55+ 'Set HTML2RSS_SECRET_KEY environment variable for production use.'
56+ )
57+ nil
5458 end
5559
5660 def show_production_error
57- puts production_error_message
61+ SecurityLogger . log_config_validation_failure ( 'secret_key' , 'Missing required secret key' )
62+ warn_lines ( *production_error_message . lines ( chomp : true ) )
5863 exit 1
5964 end
6065
@@ -79,9 +84,11 @@ def validate_secret_key!
7984 return unless secret == 'your-generated-secret-key-here' || secret . length < 32
8085
8186 SecurityLogger . log_config_validation_failure ( 'secret_key' , 'Invalid or weak secret key' )
82- puts '❌ CRITICAL: Invalid secret key for production deployment!'
83- puts ' Secret key must be at least 32 characters and not the default placeholder.'
84- puts ' Generate a secure key: openssl rand -hex 32'
87+ warn_lines (
88+ 'CRITICAL: Invalid secret key for production deployment!' ,
89+ 'Secret key must be at least 32 characters and not the default placeholder.' ,
90+ 'Generate a secure key: openssl rand -hex 32'
91+ )
8592 exit 1
8693 end
8794
@@ -90,11 +97,35 @@ def validate_account_configuration!
9097 weak_tokens = accounts . select { |acc | acc [ :token ] . length < 16 }
9198 return unless weak_tokens . any?
9299
100+ handle_weak_account_tokens! ( weak_tokens )
101+ end
102+
103+ # @param lines [Array<String>]
104+ # @return [void]
105+ def warn_lines ( *lines )
106+ lines . each { |line | Kernel . warn ( line ) }
107+ nil
108+ end
109+
110+ # @return [void]
111+ def log_development_default_secret_key_warning
112+ SecurityLogger . log_config_validation_failure (
113+ 'secret_key' ,
114+ 'Using development default secret key' ,
115+ severity : :warn
116+ )
117+ end
118+
119+ # @param weak_tokens [Array<Hash{Symbol=>String}>]
120+ # @return [void]
121+ def handle_weak_account_tokens! ( weak_tokens )
93122 weak_usernames = weak_tokens . map { |acc | acc [ :username ] } . join ( ', ' )
94123 SecurityLogger . log_config_validation_failure ( 'account_tokens' , "Weak tokens for users: #{ weak_usernames } " )
95- puts '❌ CRITICAL: Weak authentication tokens detected in production!'
96- puts ' All tokens must be at least 16 characters long.'
97- puts " Weak tokens found for users: #{ weak_usernames } "
124+ warn_lines (
125+ 'CRITICAL: Weak authentication tokens detected in production!' ,
126+ 'All tokens must be at least 16 characters long.' ,
127+ "Weak tokens found for users: #{ weak_usernames } "
128+ )
98129 exit 1
99130 end
100131 end
0 commit comments