summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2018-06-19 23:01:56 +0000
committerAlessio Caiazza <acaiazza@gitlab.com>2018-06-21 10:01:55 +0200
commitfe2c4258923eb1c870d2ee9dd4ac43b988fde11f (patch)
treefbd1f07cf5197af252fe0881015129774ed8f828
parentb84bfb5d66ef230bf0609bed2524e187d3654ed6 (diff)
downloadgitlab-ce-fe2c4258923eb1c870d2ee9dd4ac43b988fde11f.tar.gz
Merge branch 'security-2682-fix-xss-for-markdown-toc-11-0' into 'security-11-0'
[11.0] Fix xss for Markdown elements where [[_TOC_]] is enabled See merge request gitlab/gitlabhq!2412
-rw-r--r--changelogs/unreleased/security-2682-fix-xss-for-markdown-toc.yml5
-rw-r--r--lib/banzai/filter/table_of_contents_filter.rb2
-rw-r--r--spec/lib/banzai/filter/table_of_contents_filter_spec.rb9
3 files changed, 15 insertions, 1 deletions
diff --git a/changelogs/unreleased/security-2682-fix-xss-for-markdown-toc.yml b/changelogs/unreleased/security-2682-fix-xss-for-markdown-toc.yml
new file mode 100644
index 00000000000..f595678c3c2
--- /dev/null
+++ b/changelogs/unreleased/security-2682-fix-xss-for-markdown-toc.yml
@@ -0,0 +1,5 @@
+---
+title: Fix XSS vulnerability for table of content generation
+merge_request:
+author:
+type: security
diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb
index 97244159985..b32660a8341 100644
--- a/lib/banzai/filter/table_of_contents_filter.rb
+++ b/lib/banzai/filter/table_of_contents_filter.rb
@@ -92,7 +92,7 @@ module Banzai
def text
return '' unless node
- @text ||= node.text
+ @text ||= EscapeUtils.escape_html(node.text)
end
private
diff --git a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
index 0cfef4ff5bf..7213cd58ea7 100644
--- a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
+++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
@@ -139,5 +139,14 @@ describe Banzai::Filter::TableOfContentsFilter do
expect(items[5].ancestors).to include(items[4])
end
end
+
+ context 'header text contains escaped content' do
+ let(:content) { '&lt;img src="x" onerror="alert(42)"&gt;' }
+ let(:results) { result(header(1, content)) }
+
+ it 'outputs escaped content' do
+ expect(doc.inner_html).to include(content)
+ end
+ end
end
end