diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-10-01 23:40:29 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-10-01 23:40:29 -0400 |
commit | 16f8ca566b8637dc8092a6b630c23a82a905b437 (patch) | |
tree | 18aa607e127d8a62ed2b99208504674274d2b5e8 /lib | |
parent | d7eceafb27225dee1b62181c21ae7cc240d984bf (diff) | |
download | gitlab-ce-16f8ca566b8637dc8092a6b630c23a82a905b437.tar.gz |
Add custom protocol whitelisting to SanitizationFilterrs-dev-issue-2613
Addresses internal https://dev.gitlab.org/gitlab/gitlabhq/issues/2613
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/markdown/sanitization_filter.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/gitlab/markdown/sanitization_filter.rb b/lib/gitlab/markdown/sanitization_filter.rb index e368de7d848..ffb9dc33b64 100644 --- a/lib/gitlab/markdown/sanitization_filter.rb +++ b/lib/gitlab/markdown/sanitization_filter.rb @@ -48,6 +48,12 @@ module Gitlab # Allow span elements whitelist[:elements].push('span') + # Allow any protocol in `a` elements... + whitelist[:protocols].delete('a') + + # ...but then remove links with the `javascript` protocol + whitelist[:transformers].push(remove_javascript_links) + # Remove `rel` attribute from `a` elements whitelist[:transformers].push(remove_rel) @@ -57,6 +63,19 @@ module Gitlab whitelist end + def remove_javascript_links + lambda do |env| + node = env[:node] + + return unless node.name == 'a' + return unless node.has_attribute?('href') + + if node['href'].start_with?('javascript', ':javascript') + node.remove_attribute('href') + end + end + end + def remove_rel lambda do |env| if env[:node_name] == 'a' |