Class: Brakeman::CheckFileAccess

Inherits:
BaseCheck
  • Object
show all
Defined in:
lib/brakeman/checks/check_file_access.rb

Overview

Checks for user input in methods which open or manipulate files

Direct Known Subclasses

CheckSendFile

Constant Summary

Constant Summary

Constants inherited from BaseCheck

BaseCheck::CONFIDENCE

Constants included from Util

Util::ALL_PARAMETERS, Util::COOKIES, Util::PARAMETERS, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_PARAMETERS, Util::SESSION

Instance Attribute Summary

Attributes inherited from BaseCheck

#tracker, #warnings

Instance Method Summary (collapse)

Methods inherited from BaseCheck

#add_result, #initialize, #process_call, #process_cookies, #process_default, #process_params

Methods included from Util

#array?, #call?, #camelize, #cookies?, #false?, #hash?, #hash_insert, #hash_iterate, #integer?, #number?, #params?, #pluralize, #regexp?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #true?, #underscore

Methods included from ProcessorHelper

#class_name, #process_module

Constructor Details

This class inherits a constructor from Brakeman::BaseCheck

Instance Method Details

- (Object) process_result(result)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/brakeman/checks/check_file_access.rb', line 24

def process_result result
  call = result[:call]

  file_name = call[3][1]

  if check = include_user_input?(file_name)
    unless duplicate? result
      add_result result

      if check == :params
        message = "Parameter"
      elsif check == :cookies
        message = "Cookie"
      else
        message = "User input"
      end

      message << " value used in file name"

      warn :result => result,
        :warning_type => "File Access",
        :message => message, 
        :confidence => CONFIDENCE[:high],
        :line => call.line,
        :code => call
    end
  end
end

- (Object) run_check



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/brakeman/checks/check_file_access.rb', line 8

def run_check
  debug_info "Finding possible file access"
  methods = tracker.find_call :targets => [:Dir, :File, :IO, :Kernel, :Net::FTP", :Net::HTTP", :PStore, :Pathname, :Shell, :YAML], :methods => [:[], :chdir, :chroot, :delete, :entries, :foreach, :glob, :install, :lchmod, :lchown, :link, :load, :load_file, :makedirs, :move, :new, :open, :read, :read_lines, :rename, :rmdir, :safe_unlink, :symlink, :syscopy, :sysopen, :truncate, :unlink]

  debug_info "Finding calls to load()"
  methods.concat tracker.find_call :target => false, :method => :load

  debug_info "Finding calls using FileUtils"
  methods.concat tracker.find_call :target => :FileUtils

  debug_info "Processing found calls"
  methods.each do |call|
    process_result call
  end
end