Class: Hedra::SecurityTxtChecker
- Inherits:
-
Object
- Object
- Hedra::SecurityTxtChecker
- Defined in:
- lib/hedra/security_txt_checker.rb
Overview
Check for security.txt file (RFC 9116)
Constant Summary collapse
- SECURITY_TXT_PATHS =
[ '/.well-known/security.txt', '/security.txt' ].freeze
Instance Method Summary collapse
Instance Method Details
#check(url, http_client) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hedra/security_txt_checker.rb', line 11 def check(url, http_client) uri = URI.parse(url) base_url = "#{uri.scheme}://#{uri.host}#{":#{uri.port}" if uri.port && ![80, 443].include?(uri.port)}" findings = [] found = false SECURITY_TXT_PATHS.each do |path| response = http_client.get("#{base_url}#{path}") if response.status.success? found = true findings.concat(validate_security_txt(response.body.to_s)) break end rescue StandardError # Continue to next path end unless found findings << { header: 'security.txt', issue: 'security.txt file not found', severity: :info, recommended_fix: 'Add security.txt file at /.well-known/security.txt' } end findings rescue StandardError => e warn "security.txt check failed: #{e.message}" [] end |