Merge branch 'security-label-xss' into 'master'

[master] Escape html entities when no label found

See merge request gitlab/gitlabhq!2706
This commit is contained in:
John Jarvis 2019-01-02 09:34:13 +00:00
commit 90e1f10f07
3 changed files with 28 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
title: Escape html entities in LabelReferenceFilter when no label found
merge_request:
author:
type: security

View file

@ -29,7 +29,7 @@ module Banzai
if label
yield match, label.id, project, namespace, $~
else
match
escape_html_entities(match)
end
end
end
@ -102,6 +102,10 @@ module Banzai
CGI.unescapeHTML(text.to_s)
end
def escape_html_entities(text)
CGI.escapeHTML(text.to_s)
end
def object_link_title(object, matches)
# use title of wrapped element instead
nil

View file

@ -236,6 +236,24 @@ describe Banzai::Filter::LabelReferenceFilter do
end
end
context 'References with html entities' do
let!(:label) { create(:label, name: '<html>', project: project) }
it 'links to a valid reference' do
doc = reference_filter('See ~"<html>"')
expect(doc.css('a').first.attr('href')).to eq urls
.project_issues_url(project, label_name: label.name)
expect(doc.text).to eq 'See <html>'
end
it 'ignores invalid label names and escapes entities' do
act = %(Label #{Label.reference_prefix}"&lt;non valid&gt;")
expect(reference_filter(act).to_html).to eq act
end
end
describe 'consecutive references' do
let(:bug) { create(:label, name: 'bug', project: project) }
let(:feature_proposal) { create(:label, name: 'feature proposal', project: project) }