diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-03-14 16:07:51 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-03-14 18:05:01 -0400 |
commit | 41de7b345b0abdaba2f0d7614ebdb1cc7310a5fb (patch) | |
tree | 2d6f9353aeab777469fee6fbcf66c0b8d1ab2cf2 /lib | |
parent | b782e7c9732275175d79b485fcddc85e575d48dd (diff) | |
download | gitlab-ce-41de7b345b0abdaba2f0d7614ebdb1cc7310a5fb.tar.gz |
Be more intelligent about sanitizing links with unsafe protocolsrs-issue-14220
This prevents false matches on relative links like
`[database](database.md)`.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/14220
Diffstat (limited to 'lib')
-rw-r--r-- | lib/banzai/filter/sanitization_filter.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/banzai/filter/sanitization_filter.rb b/lib/banzai/filter/sanitization_filter.rb index abd79b329ae..e8011519608 100644 --- a/lib/banzai/filter/sanitization_filter.rb +++ b/lib/banzai/filter/sanitization_filter.rb @@ -7,7 +7,7 @@ module Banzai # # Extends HTML::Pipeline::SanitizationFilter with a custom whitelist. class SanitizationFilter < HTML::Pipeline::SanitizationFilter - UNSAFE_PROTOCOLS = %w(javascript :javascript data vbscript).freeze + UNSAFE_PROTOCOLS = %w(data javascript vbscript).freeze def whitelist whitelist = super @@ -64,7 +64,12 @@ module Banzai return unless node.name == 'a' return unless node.has_attribute?('href') - if node['href'].start_with?(*UNSAFE_PROTOCOLS) + begin + uri = Addressable::URI.parse(node['href']) + uri.scheme.strip! if uri.scheme + + node.remove_attribute('href') if UNSAFE_PROTOCOLS.include?(uri.scheme) + rescue Addressable::URI::InvalidURIError node.remove_attribute('href') end end |