Skip to content

Commit 14112bf

Browse files
committed
LibWeb/CSS: Reject filters with invalid URL references
These should make the filter list invalid, not just skip the URL.
1 parent 5ff2c71 commit 14112bf

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

Libraries/LibWeb/Painting/Paintable.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,13 +860,13 @@ ResolvedCSSFilter resolve_css_filter(CSS::Filter const& computed_filter, Paintab
860860
if (filter_operation->is_url()) {
861861
auto& url_string = filter_operation->as_url().url().url();
862862
if (url_string.is_empty() || !url_string.starts_with('#'))
863-
continue;
863+
return {};
864864
auto fragment_or_error = url_string.substring_from_byte_offset(1);
865865
if (fragment_or_error.is_error())
866-
continue;
866+
return {};
867867
auto maybe_filter = paintable_box.document().get_element_by_id(Utf16String::from_utf8(fragment_or_error.value()));
868868
if (!maybe_filter)
869-
continue;
869+
return {};
870870
if (auto* filter_element = as_if<SVG::SVGFilterElement>(*maybe_filter)) {
871871
// Filter primitive lengths are specified in the filtered element's user coordinate system, but the
872872
// resulting filter operates in device pixels. Compute the user-unit-to-device-pixel scale so the
@@ -885,6 +885,8 @@ ResolvedCSSFilter resolve_css_filter(CSS::Filter const& computed_filter, Paintab
885885
}
886886
if (!bounds.is_empty())
887887
result.svg_filter_bounds = bounds;
888+
} else {
889+
return {};
888890
}
889891
continue;
890892
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<style>
3+
.box {
4+
display: inline-block;
5+
width: 40px;
6+
height: 40px;
7+
margin: 20px;
8+
background: black;
9+
}
10+
</style>
11+
<div class="box"></div>
12+
<div class="box"></div>
13+
<div class="box"></div>
14+
<div class="box"></div>
15+
<div class="box"></div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype html>
2+
<link rel="match" href="../expected/css-filter-invalid-url-ref.html" />
3+
<style>
4+
#not-a-filter {
5+
display: none;
6+
}
7+
.box {
8+
display: inline-block;
9+
width: 40px;
10+
height: 40px;
11+
margin: 20px;
12+
background: black;
13+
}
14+
#empty-url { filter: url("") blur(5px); }
15+
#external-url { filter: url("filter.svg#filter") blur(5px); }
16+
#empty-fragment { filter: url("#") blur(5px); }
17+
#missing-element { filter: url("#missing") blur(5px); }
18+
#wrong-element { filter: url("#not-a-filter") blur(5px); }
19+
</style>
20+
<div id="not-a-filter"></div>
21+
<div class="box" id="empty-url"></div>
22+
<div class="box" id="external-url"></div>
23+
<div class="box" id="empty-fragment"></div>
24+
<div class="box" id="missing-element"></div>
25+
<div class="box" id="wrong-element"></div>

0 commit comments

Comments
 (0)