Skip to content
Snippets Groups Projects
Commit b33b170a authored by Heinrich Lee Yu's avatar Heinrich Lee Yu :basketball: Committed by GitLab Release Tools Bot
Browse files

Escape original content in reference redactor

Merge branch 'security-fix-reference-redactor-xss-14-9' into '14-9-stable-ee'

See merge request gitlab-org/security/gitlab!2317

Changelog: security
parent 999a4a9a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -65,16 +65,15 @@ module Banzai
#
def redacted_node_content(node)
original_content = node.attr('data-original')
link_reference = node.attr('data-link-reference')
original_content = CGI.escape_html(original_content) if original_content
 
# Build the raw <a> tag just with a link as href and content if
# it's originally a link pattern. We shouldn't return a plain text href.
original_link =
if link_reference == 'true'
if node.attr('data-link-reference') == 'true'
href = node.attr('href')
content = original_content
 
%(<a href="#{href}">#{content}</a>)
%(<a href="#{href}">#{original_content}</a>)
end
 
# The reference should be replaced by the original link's content,
Loading
Loading
Loading
Loading
@@ -35,7 +35,7 @@ RSpec.describe Banzai::ReferenceRedactor do
end
 
context 'when data-original attribute provided' do
let(:original_content) { '<code>foo</code>' }
let(:original_content) { '&lt;script&gt;alert(1);&lt;/script&gt;' }
 
it 'replaces redacted reference with original content' do
doc = Nokogiri::HTML.fragment("<a class='gfm' href='https://www.gitlab.com' data-reference-type='issue' data-original='#{original_content}'>bar</a>")
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment