Commit 4acab552 authored by Douwe Maan's avatar Douwe Maan Committed by Robert Speicher

Merge branch 'fix-escape-commit-block' into 'security-9-5'

[9.5] Prevent a persistent XSS in the commit author block

See merge request gitlab/gitlabhq!2180
parent 941a2d27
......@@ -137,7 +137,7 @@ module CommitsHelper
text =
if options[:avatar]
%Q{<span class="commit-#{options[:source]}-name">#{person_name}</span>}
content_tag(:span, person_name, class: "commit-#{options[:source]}-name")
else
person_name
end
......@@ -148,9 +148,9 @@ module CommitsHelper
}
if user.nil?
mail_to(source_email, text.html_safe, options)
mail_to(source_email, text, options)
else
link_to(text.html_safe, user_path(user), options)
link_to(text, user_path(user), options)
end
end
......
---
title: Prevent a persistent XSS in the commit author block
merge_request:
author:
type: security
......@@ -12,6 +12,17 @@ describe CommitsHelper do
expect(helper.commit_author_link(commit))
.not_to include('onmouseover="alert(1)"')
end
it 'escapes the author name' do
user = build_stubbed(:user, name: 'Foo <script>alert("XSS")</script>')
commit = double(author: user, author_name: '', author_email: '')
expect(helper.commit_author_link(commit))
.to include('Foo &lt;script&gt;')
expect(helper.commit_author_link(commit, avatar: true))
.to include('commit-author-name', 'Foo &lt;script&gt;')
end
end
describe 'commit_committer_link' do
......@@ -25,6 +36,17 @@ describe CommitsHelper do
expect(helper.commit_committer_link(commit))
.not_to include('onmouseover="alert(1)"')
end
it 'escapes the commiter name' do
user = build_stubbed(:user, name: 'Foo <script>alert("XSS")</script>')
commit = double(committer: user, committer_name: '', committer_email: '')
expect(helper.commit_committer_link(commit))
.to include('Foo &lt;script&gt;')
expect(helper.commit_committer_link(commit, avatar: true))
.to include('commit-committer-name', 'Foo &lt;script&gt;')
end
end
describe '#view_on_environment_button' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment