Skip to content

Commit b4d07f8

Browse files
No attribute name XSS warning in Rails 6.1.6+ (#1779)
Fixes #1778
1 parent 38306e2 commit b4d07f8

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

lib/brakeman/checks/check_content_tag.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ def process_result result
7373
check_argument result, content
7474
end
7575

76-
#Attribute keys are never escaped, so check them for user input
77-
if not @matched and hash? attributes and not request_value? attributes
78-
hash_iterate(attributes) do |k, _v|
79-
check_argument result, k
80-
return if @matched
76+
# This changed in Rails 6.1.6
77+
if version_between? '0.0.0', '6.1.5'
78+
#Attribute keys are never escaped, so check them for user input
79+
if not @matched and hash? attributes and not request_value? attributes
80+
hash_iterate(attributes) do |k, _v|
81+
check_argument result, k
82+
return if @matched
83+
end
8184
end
8285
end
8386

test/tests/rails7.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ def test_cross_site_scripting_CVE_2022_32209_allowed_tags_initializer
313313
user_input: nil
314314
end
315315

316+
def test_cross_site_scripting_content_tag
317+
assert_no_warning check_name: "ContentTag",
318+
type: :template,
319+
warning_code: 53,
320+
warning_type: "Cross-Site Scripting",
321+
line: 2,
322+
message: /^Unescaped\ parameter\ value\ in\ `content_ta/,
323+
confidence: 0,
324+
relative_path: "app/views/users/index.html.erb",
325+
code: s(:call, nil, :content_tag, s(:lit, :b), s(:call, nil, :cool_content), s(:hash, s(:call, s(:call, nil, :params), :[], s(:lit, :stuff)), s(:call, s(:call, nil, :params), :[], s(:lit, :things)))),
326+
user_input: s(:call, s(:call, nil, :params), :[], s(:lit, :stuff))
327+
end
328+
316329
def test_redirect_1
317330
assert_warning check_name: "Redirect",
318331
type: :warning,

0 commit comments

Comments
 (0)