Class: Rails::Guarddog::Checkers::OpenRedirectChecker

Inherits:
BaseChecker
  • Object
show all
Defined in:
lib/rails/guarddog/checkers/open_redirect_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/open_redirect_checker.rb', line 5

def run
  glob_files('app/controllers/**/*.rb').each do |file|
    content = File.read(file)
    content.each_line.with_index do |line, idx|
      if line.match?(/redirect_to\s+params\[:/) || line.match?(/redirect_to\s+request\./)
        add_finding(
          severity: :high,
          message: "Potential open redirect: user-controlled redirect URL",
          file: file,
          line: idx + 1,
          snippet: line.strip,
          remediation: "Whitelist allowed redirect URLs"
        )
      end
    end
  end
  findings
end