diff options
author | Robert Speicher <robert@gitlab.com> | 2017-02-08 20:33:29 +0000 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2017-02-15 10:41:40 -0500 |
commit | 33c8d413d2b42bd7b823228a2739eddcd4dfbe51 (patch) | |
tree | fb10bca9ae43135427ee08896733d4d255c03981 /spec/lib | |
parent | 4ca6a719a9f961efa8e9b2a9401319cbfc6403df (diff) | |
download | gitlab-ce-33c8d413d2b42bd7b823228a2739eddcd4dfbe51.tar.gz |
Merge branch 'asciidoctor-xss-patch' into 'security'
Add sanitization filter to asciidocs output to prevent XSS
See https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2057
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/asciidoc_spec.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb index ba199917f5c..bca57105d1d 100644 --- a/spec/lib/gitlab/asciidoc_spec.rb +++ b/spec/lib/gitlab/asciidoc_spec.rb @@ -41,6 +41,29 @@ module Gitlab render(input, context, asciidoc_opts) end end + + context "XSS" do + links = { + 'links' => { + input: 'link:mylink"onmouseover="alert(1)[Click Here]', + output: "<div>\n<p><a href=\"mylink\">Click Here</a></p>\n</div>" + }, + 'images' => { + input: 'image:https://localhost.com/image.png[Alt text" onerror="alert(7)]', + output: "<div>\n<p><span><img src=\"https://localhost.com/image.png\" alt=\"Alt text\"></span></p>\n</div>" + }, + 'pre' => { + input: '```mypre"><script>alert(3)</script>', + output: "<div>\n<div>\n<pre lang=\"mypre\">\"><code></code></pre>\n</div>\n</div>" + } + } + + links.each do |name, data| + it "does not convert dangerous #{name} into HTML" do + expect(render(data[:input], context)).to eql data[:output] + end + end + end end def render(*args) |