Commit c3bda6c3 authored by Robert Speicher's avatar Robert Speicher

Re-allow `name` attribute on user-provided anchor HTML

parent f9df0e13
---
title: Re-allow `name` attribute on user-provided anchor HTML
merge_request:
author:
type: fixed
...@@ -45,8 +45,9 @@ module Banzai ...@@ -45,8 +45,9 @@ module Banzai
whitelist[:elements].push('abbr') whitelist[:elements].push('abbr')
whitelist[:attributes]['abbr'] = %w(title) whitelist[:attributes]['abbr'] = %w(title)
# Disallow `name` attribute globally # Disallow `name` attribute globally, allow on `a`
whitelist[:attributes][:all].delete('name') whitelist[:attributes][:all].delete('name')
whitelist[:attributes]['a'].push('name')
# Allow any protocol in `a` elements... # Allow any protocol in `a` elements...
whitelist[:protocols].delete('a') whitelist[:protocols].delete('a')
......
...@@ -101,16 +101,18 @@ describe Banzai::Filter::SanitizationFilter do ...@@ -101,16 +101,18 @@ describe Banzai::Filter::SanitizationFilter do
expect(filter(act).to_html).to eq exp expect(filter(act).to_html).to eq exp
end end
it 'disallows the `name` attribute globally' do it 'disallows the `name` attribute globally, allows on `a`' do
html = <<~HTML html = <<~HTML
<img name="getElementById" src=""> <img name="getElementById" src="">
<span name="foo" class="bar">Hi</span> <span name="foo" class="bar">Hi</span>
<a name="foo" class="bar">Bye</a>
HTML HTML
doc = filter(html) doc = filter(html)
expect(doc.at_css('img')).not_to have_attribute('name') expect(doc.at_css('img')).not_to have_attribute('name')
expect(doc.at_css('span')).not_to have_attribute('name') expect(doc.at_css('span')).not_to have_attribute('name')
expect(doc.at_css('a')).to have_attribute('name')
end end
it 'allows `summary` elements' do it 'allows `summary` elements' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment