From 41de7b345b0abdaba2f0d7614ebdb1cc7310a5fb Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 14 Mar 2016 16:07:51 -0400 Subject: 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 --- spec/lib/banzai/filter/sanitization_filter_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec') 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: '' }, + 'protocol-based JS injection: invalid URL char' => { + input: '', + output: '' + }, + 'protocol-based JS injection: spaces and entities' => { input: 'foo', output: 'foo' }, + + 'protocol whitespace' => { + input: '', + output: '' + } } protocols.each do |name, data| @@ -177,6 +187,16 @@ describe Banzai::Filter::SanitizationFilter, lib: true do expect(output.to_html).to eq 'XSS' end + it 'disallows invalid URIs' do + expect(Addressable::URI).to receive(:parse).with('foo://example.com'). + and_raise(Addressable::URI::InvalidURIError) + + input = 'Foo' + output = filter(input) + + expect(output.to_html).to eq 'Foo' + end + it 'allows non-standard anchor schemes' do exp = %q{IRC} act = filter(exp) -- cgit v1.2.1