11
12
13
14
15
16
17
18
19
20
21
22
23
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
52
53
54
55
56
|
# File 'lib/tainted_love/replacer/replace_rails_user_input.rb', line 11
def replace!
TaintedLove.proxy_method('ActionDispatch::Http::Headers', :[]) do |return_value, *_args|
return_value.taint
end
if Object.const_defined?('ActiveRecord::Base')
ActiveRecord::Base.after_find do
attributes.values.each do |value|
value.taint unless value.frozen?
end
end
end
if Object.const_defined?('ActionController::Base')
ActionController::Base.class_eval do
before_action :taint_params
before_action :taint_cookies
private
def taint_params(value = params)
if value.is_a?(ActionController::Parameters) || value.is_a?(ActiveSupport::HashWithIndifferentAccess)
value.values.map { |x| x.taint unless x.frozen? }
value.values.each { |x| taint_params(x) }
else
value.taint unless value.frozen?
end
end
def taint_cookies
request.cookies.values.each(&:taint)
end
end
end
if Object.const_defined?('ActionController::Parameters')
ActionController::Parameters.class_eval do
def keys
@parameters.keys.map { |key| key.dup.taint }
end
end
end
end
|