class TaintedLove::Replacer::ReplaceActionController

Public Instance Methods

replace!() click to toggle source
# File lib/tainted_love/replacer/replace_action_controller.rb, line 10
def replace!
  TaintedLove.proxy_method('ActionController::Instrumentation', :send_file) do |_, *args|
    TaintedLove.report(
      :ReplaceActionController,
      args.first,
      [:lfi],
      'Sendfile using tainted file name'
    ) if args.first.tainted?
  end

  TaintedLove.proxy_method('ActionController::Instrumentation', :render) do |_, *args|
    unless args.empty?
      f = args.first

      if f.is_a?(Hash)
        if f.key?(:inline) && f[:inline].tainted?
          TaintedLove.report(
            :ReplaceActionController,
            f[:inline],
            [:rce],
            'render(inline:) using tainted string'
          )
        end

        if f.key?(:file) && f[:file].tainted?
          TaintedLove.report(
            :ReplaceActionController,
            f[:file],
            [:lfi],
            'render(file:) using tainted file name'
          )
        end
      end

      if f.is_a?(String) && f.tainted?
        TaintedLove.report(
          :ReplaceActionController,
          f,
          [:lfi],
          'render using tainted template name'
        )
      end
    end
  end
end
should_replace?() click to toggle source
# File lib/tainted_love/replacer/replace_action_controller.rb, line 6
def should_replace?
  Object.const_defined?('ActionController')
end