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
57
58
|
# File 'lib/brakeman/checks/check_reverse_tabnabbing.rb', line 15
def process_result result
return unless original? result and result[:call].last_arg
html_opts = result[:call].last_arg
return unless hash? html_opts
target = hash_access html_opts, :target
unless target &&
(string?(target) && target.value == "_blank" ||
symbol?(target) && target.value == :_blank)
return
end
target_url = result[:block] ? result[:call].first_arg : result[:call].second_arg
return if !call?(target_url) || target_url.method.match(/^url_for$|_path$/)
rel = hash_access html_opts, :rel
confidence = :medium
if rel && string?(rel) then
rel_opt = rel.value
return if rel_opt.include?("noopener") && rel_opt.include?("noreferrer")
if rel_opt.include?("noopener") ^ rel_opt.include?("noreferrer") then
confidence = :weak
end
end
warn :result => result,
:warning_type => "Reverse Tabnabbing",
:warning_code => :reverse_tabnabbing,
:message => msg("When opening a link in a new tab without setting ", msg_code('rel: "noopener noreferrer"'),
", the new tab can control the parent tab's location. For example, an attacker could redirect to a phishing page."),
:confidence => confidence,
:user_input => rel,
:cwe_id => [1022]
end
|