Class: Rails::Guarddog::Checkers::AiInjectionChecker
- Inherits:
-
BaseChecker
- Object
- BaseChecker
- Rails::Guarddog::Checkers::AiInjectionChecker
- Defined in:
- lib/rails/guarddog/checkers/ai_injection_checker.rb
Constant Summary collapse
- AI_GEMS =
%w[ruby-openai anthropic langchainrb openai]
Instance Attribute Summary
Attributes inherited from BaseChecker
Instance Method Summary collapse
Methods inherited from BaseChecker
Constructor Details
This class inherits a constructor from Rails::Guarddog::Checkers::BaseChecker
Instance Method Details
#run ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rails/guarddog/checkers/ai_injection_checker.rb', line 7 def run glob_files('app/**/*.rb').each do |file| content = File.read(file) content.each_line.with_index do |line, idx| # Check for AI gem calls with user input if line.match?(/\.create.*messages/) || line.match?(/\.chat\.completions/) if line.include?('params') || line.include?('user_input') add_finding( severity: :critical, message: "AI prompt injection risk: user input passed to LLM without sanitization", file: file, line: idx + 1, snippet: line.strip, remediation: "Sanitize user input before passing to LLM; use system prompts safely" ) end end end end findings end |