Class: Rails::Guarddog::Checkers::XssChecker

Inherits:
BaseChecker
  • Object
show all
Defined in:
lib/rails/guarddog/checkers/xss_checker.rb

Instance Attribute Summary

Attributes inherited from BaseChecker

#findings

Instance Method Summary collapse

Methods inherited from BaseChecker

#initialize

Constructor Details

This class inherits a constructor from Rails::Guarddog::Checkers::BaseChecker

Instance Method Details

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rails/guarddog/checkers/xss_checker.rb', line 5

def run
  glob_files('app/views/**/*.erb').each do |file|
    content = File.read(file)
    content.each_line.with_index do |line, idx|
      if xss_vulnerable?(line)
        add_finding(
          severity: :high,
          message: "Potential XSS vulnerability: unescaped output detected",
          file: file,
          line: idx + 1,
          snippet: line.strip,
          remediation: "Use <%= h() %> or sanitize() instead of raw/html_safe"
        )
      end
    end
  end
  findings
end