diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-03-15 08:29:04 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-03-15 08:29:04 +0000 |
commit | a60e09d3134379925fdab2a6f1d3c5852a3f6978 (patch) | |
tree | 2521becb105d2378fdd907a8d5121d8ceb91e673 /spec | |
parent | c4b35a623016bb8a3402d9a53fb9df7a990ad9aa (diff) | |
parent | 41de7b345b0abdaba2f0d7614ebdb1cc7310a5fb (diff) | |
download | gitlab-ce-a60e09d3134379925fdab2a6f1d3c5852a3f6978.tar.gz |
Merge branch 'rs-issue-14220' into 'master'
Be more intelligent about sanitizing links with unsafe protocols
This prevents false matches on relative links like
`[database](database.md)`.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/14220
See merge request !3210
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/banzai/filter/sanitization_filter_spec.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/sanitization_filter_spec.rb b/spec/lib/banzai/filter/sanitization_filter_spec.rb index 4a7b00c7660..27ce312b11c 100644 --- a/spec/lib/banzai/filter/sanitization_filter_spec.rb +++ b/spec/lib/banzai/filter/sanitization_filter_spec.rb @@ -149,10 +149,20 @@ describe Banzai::Filter::SanitizationFilter, lib: true do output: '<a href="java"></a>' }, + 'protocol-based JS injection: invalid URL char' => { + input: '<img src=java\script:alert("XSS")>', + output: '<img>' + }, + 'protocol-based JS injection: spaces and entities' => { input: '<a href="  javascript:alert(\'XSS\');">foo</a>', output: '<a href="">foo</a>' }, + + 'protocol whitespace' => { + input: '<a href=" http://example.com/"></a>', + output: '<a href="http://example.com/"></a>' + } } protocols.each do |name, data| @@ -177,6 +187,16 @@ describe Banzai::Filter::SanitizationFilter, lib: true do expect(output.to_html).to eq '<a>XSS</a>' end + it 'disallows invalid URIs' do + expect(Addressable::URI).to receive(:parse).with('foo://example.com'). + and_raise(Addressable::URI::InvalidURIError) + + input = '<a href="foo://example.com">Foo</a>' + output = filter(input) + + expect(output.to_html).to eq '<a>Foo</a>' + end + it 'allows non-standard anchor schemes' do exp = %q{<a href="irc://irc.freenode.net/git">IRC</a>} act = filter(exp) |