Defect #44586 ยป 0004-Stop-escaping-the-attributes-of-the-HTML-tags-allowe.patch
| lib/redmine/wiki_formatting/textile/redcloth3.rb | ||
|---|---|---|
|
all, tag, close = $1, $2, $3
|
||
|
if close.present? && (ALLOWED_TAGS.include?(tag) || (tag =~ /\Aredpre#\d+\z/))
|
||
|
"<#{htmlesc all}#{close}"
|
||
|
"<#{all}#{close}"
|
||
|
else
|
||
|
"<#{htmlesc all}#{'>' unless close.blank?}"
|
||
|
end
|
||
| lib/redmine/wiki_formatting/textile/sanitization_filter.rb | ||
|---|---|---|
|
def default_allowlist
|
||
|
allowlist = super
|
||
|
allowlist[:elements] += %w[font]
|
||
|
allowlist[:attributes][:all] += %w[class id]
|
||
|
allowlist[:attributes]['font'] = %w[face]
|
||
|
allowlist
|
||
|
end
|
||
| test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb | ||
|---|---|---|
|
assert_includes to_html(%{version:"foo <bar>"}), %{version:"foo <bar>"}
|
||
|
end
|
||
|
def test_should_keep_quoted_attributes_of_allowed_tags
|
||
|
with_allowed_tags('font', 'a') do
|
||
|
assert_html_output(
|
||
|
{
|
||
|
%{<font color="red" size='3'>text</font>} => '<font color="red" size="3">text</font>',
|
||
|
'<a href="https://example.com/" title="Example">text</a>' =>
|
||
|
'<p><a href="https://example.com/" title="Example">text</a></p>',
|
||
|
},
|
||
|
false
|
||
|
)
|
||
|
end
|
||
|
end
|
||
|
def test_should_remove_unsafe_attributes_from_allowed_tags
|
||
|
with_allowed_tags('a') do
|
||
|
assert_html_output(
|
||
|
{
|
||
|
'<a href="javascript:alert(1)">text</a>' => '<p><a>text</a></p>',
|
||
|
'<a href="/" onclick="alert(1)">text</a>' => '<p><a href="/">text</a></p>',
|
||
|
},
|
||
|
false
|
||
|
)
|
||
|
end
|
||
|
end
|
||
|
def test_nested_notextile_tag_boundaries
|
||
|
["<<notextile>div class=foo >",
|
||
|
"<</notextile>div class=foo >"].each do |payload|
|
||
| ... | ... | |
|
private
|
||
|
def with_allowed_tags(*tags)
|
||
|
allowed_tags = Redmine::WikiFormatting::Textile::Filter::ALLOWED_TAGS
|
||
|
original_tags = allowed_tags.dup
|
||
|
allowed_tags.concat(tags)
|
||
|
yield
|
||
|
ensure
|
||
|
allowed_tags.replace(original_tags)
|
||
|
end
|
||
|
def assert_html_output(to_test, expect_paragraph = true)
|
||
|
to_test.each do |text, expected|
|
||
|
assert_equal(
|
||