summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-03-15 08:29:04 +0000
committerDouwe Maan <douwe@gitlab.com>2016-03-15 08:29:04 +0000
commita60e09d3134379925fdab2a6f1d3c5852a3f6978 (patch)
tree2521becb105d2378fdd907a8d5121d8ceb91e673 /lib
parentc4b35a623016bb8a3402d9a53fb9df7a990ad9aa (diff)
parent41de7b345b0abdaba2f0d7614ebdb1cc7310a5fb (diff)
downloadgitlab-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 'lib')
-rw-r--r--lib/banzai/filter/sanitization_filter.rb9
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