Commit 1fbf6f18 authored by Imre Farkas's avatar Imre Farkas

HTML escape the name of the user in ProjectsHelper#link_to_member

parent a8445cc2
...@@ -40,7 +40,8 @@ module ProjectsHelper ...@@ -40,7 +40,8 @@ module ProjectsHelper
name_tag_options[:class] << 'has-tooltip' name_tag_options[:class] << 'has-tooltip'
end end
content_tag(:span, sanitize(username), name_tag_options) # NOTE: ActionView::Helpers::TagHelper#content_tag HTML escapes username
content_tag(:span, username, name_tag_options)
end end
def link_to_member(project, author, opts = {}, &block) def link_to_member(project, author, opts = {}, &block)
......
---
title: HTML escape the name of the user in ProjectsHelper#link_to_member
merge_request:
author:
type: security
...@@ -248,7 +248,7 @@ describe ProjectsHelper do ...@@ -248,7 +248,7 @@ describe ProjectsHelper do
describe '#link_to_member' do describe '#link_to_member' do
let(:group) { build_stubbed(:group) } let(:group) { build_stubbed(:group) }
let(:project) { build_stubbed(:project, group: group) } let(:project) { build_stubbed(:project, group: group) }
let(:user) { build_stubbed(:user) } let(:user) { build_stubbed(:user, name: '<h1>Administrator</h1>') }
describe 'using the default options' do describe 'using the default options' do
it 'returns an HTML link to the user' do it 'returns an HTML link to the user' do
...@@ -256,6 +256,13 @@ describe ProjectsHelper do ...@@ -256,6 +256,13 @@ describe ProjectsHelper do
expect(link).to match(%r{/#{user.username}}) expect(link).to match(%r{/#{user.username}})
end end
it 'HTML escapes the name of the user' do
link = helper.link_to_member(project, user)
expect(link).to include(ERB::Util.html_escape(user.name))
expect(link).not_to include(user.name)
end
end end
end end
......
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