Module: Rollbar::RequestDataExtractor

Constant Summary collapse

ALLOWED_HEADERS_REGEX =
/^HTTP_|^CONTENT_TYPE$|^CONTENT_LENGTH$/.freeze
ALLOWED_BODY_PARSEABLE_METHODS =
%w[POST PUT PATCH DELETE].freeze

Instance Method Summary collapse

Instance Method Details

#extract_person_data_from_controller(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rollbar/request_data_extractor.rb', line 16

def extract_person_data_from_controller(env)
  if env.key?('rollbar.person_data')
    person_data = env['rollbar.person_data'] || {}
  else
    controller = env['action_controller.instance']
    person_data = begin
      controller.rollbar_person_data
    rescue StandardError
      {}
    end
  end

  person_data
end

#extract_request_data_from_rack(env) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rollbar/request_data_extractor.rb', line 31

def extract_request_data_from_rack(env)
  rack_req = ::Rack::Request.new(env)
  sensitive_params = sensitive_params_list(env)

  get_params = scrub_params(rollbar_get_params(rack_req), sensitive_params)
  post_params = scrub_params(rollbar_post_params(rack_req), sensitive_params)
  raw_body_params = scrub_params(mergeable_raw_body_params(rack_req),
                                 sensitive_params)
  cookies = scrub_params(rollbar_request_cookies(rack_req), sensitive_params)
  session = scrub_params(rollbar_request_session(env), sensitive_params)
  route_params = scrub_params(rollbar_route_params(env), sensitive_params)

  url = scrub_url(rollbar_url(env), sensitive_params)

  data = {
    :url => url,
    :params => route_params,
    :GET => get_params,
    :POST => post_params,
    :body => Rollbar::JSON.dump(raw_body_params),
    :user_ip => rollbar_user_ip(env),
    :headers => rollbar_headers(env),
    :cookies => cookies,
    :session => session,
    :method => rollbar_request_method(env)
  }

  if env['action_dispatch.request_id']
    data[:request_id] =
      env['action_dispatch.request_id']
  end

  data
end

#scrub_params(params, sensitive_params) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/rollbar/request_data_extractor.rb', line 79

def scrub_params(params, sensitive_params)
  options = {
    :params => params,
    :config => Rollbar.configuration.scrub_fields,
    :extra_fields => sensitive_params,
    :whitelist => Rollbar.configuration.scrub_whitelist
  }
  Rollbar::Scrubbers::Params.call(options)
end

#scrub_url(url, sensitive_params) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rollbar/request_data_extractor.rb', line 66

def scrub_url(url, sensitive_params)
  options = {
    :url => url,
    :scrub_fields => Array(Rollbar.configuration.scrub_fields) + sensitive_params,
    :scrub_user => Rollbar.configuration.scrub_user,
    :scrub_password => Rollbar.configuration.scrub_password,
    :randomize_scrub_length => Rollbar.configuration.randomize_scrub_length,
    :whitelist => Rollbar.configuration.scrub_whitelist
  }

  Rollbar::Scrubbers::URL.call(options)
end