Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow a few more SVG elements and attributes #246

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## next / unreleased

### Features

* Allow SVG attributes `color-profile`, `cursor`, `filter`, `marker`, and `mask`.
* Allow SVG elements `altGlyph`, `cursor`, `feImage`, `pattern`, and `tref`.


## 2.19.0 / 2022-09-14

### Features
Expand Down
10 changes: 10 additions & 0 deletions lib/loofah/html5/safelist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,19 @@ module SafeList

SVG_ELEMENTS = Set.new([
"a",
"altGlyph",
"animate",
"animateColor",
"animateMotion",
"animateTransform",
"circle",
"clipPath",
"cursor",
"defs",
"desc",
"ellipse",
"feGaussianBlur",
"feImage",
"filter",
"font-face",
"font-face-name",
Expand All @@ -207,6 +210,7 @@ module SafeList
"missing-glyph",
"mpath",
"path",
"pattern",
"polygon",
"polyline",
"radialGradient",
Expand All @@ -219,6 +223,7 @@ module SafeList
"text",
"textPath",
"title",
"tref",
"tspan",
"use",
])
Expand Down Expand Up @@ -377,8 +382,10 @@ module SafeList
"clip-rule",
"color",
"color-interpolation-filters",
"color-profile",
"color-rendering",
"content",
"cursor",
"cx",
"cy",
"d",
Expand All @@ -391,6 +398,7 @@ module SafeList
"fill",
"fill-opacity",
"fill-rule",
"filter",
"filterRes",
"filterUnits",
"font-family",
Expand All @@ -416,12 +424,14 @@ module SafeList
"keySplines",
"keyTimes",
"lang",
"marker",
"marker-end",
"marker-mid",
"marker-start",
"markerHeight",
"markerUnits",
"markerWidth",
"mask",
"maskContentUnits",
"maskUnits",
"mathematical",
Expand Down
15 changes: 15 additions & 0 deletions test/html5/test_safelist_properties.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "helper"

class Html5TestSafelistProperties < Loofah::TestCase
Loofah::HTML5::SafeList::SVG_ATTR_VAL_ALLOWS_REF.each do |attr_name|
define_method "test_svg_attr_allow_ref_#{attr_name}_is_in_svg_attributes" do
assert_includes(Loofah::HTML5::SafeList::SVG_ATTRIBUTES, attr_name)
end
end

Loofah::HTML5::SafeList::SVG_ALLOW_LOCAL_HREF.each do |attr_name|
define_method "test_svg_attr_allow_local_ref_#{attr_name}_is_in_svg_elements" do
assert_includes(Loofah::HTML5::SafeList::SVG_ELEMENTS, attr_name)
end
end
end
8 changes: 4 additions & 4 deletions test/html5/test_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ def test_figure_element_is_valid
## added because we don't have any coverage above on SVG_ATTR_VAL_ALLOWS_REF
HTML5::SafeList::SVG_ATTR_VAL_ALLOWS_REF.each do |attr_name|
define_method "test_should_allow_uri_refs_in_svg_attribute_#{attr_name}" do
input = "<rect fill='url(#foo)' />"
output = "<rect fill='url(#foo)'></rect>"
input = "<rect #{attr_name}='url(#foo)' />"
output = "<rect #{attr_name}='url(#foo)'></rect>"
check_sanitization(input, output, output, output)
end

define_method "test_absolute_uri_refs_in_svg_attribute_#{attr_name}" do
input = "<rect fill='url(http://bad.com/) #fff' />"
output = "<rect fill=' #fff'></rect>"
input = "<rect #{attr_name}='url(http://bad.com/) #fff' />"
output = "<rect #{attr_name}=' #fff'></rect>"
check_sanitization(input, output, output, output)
end
end
Expand Down