Skip to content

Truly independent web browser

LibWeb: Reject escaped registration data type names

Andreas Klingf46e165a1382
diff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax.rs
index d612f724882..d8e0bbd272a 100644
--- a/Libraries/LibWeb/Rust/src/css/parser/syntax.rs
+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax.rs
@@ -157,6 +157,15 @@ fn discard_whitespace(values: &[ComponentValue], position: &mut usize) {
}
}
+// https://drafts.css-houdini.org/css-properties-values-api/#consume-data-type-name
+// NB: Data type names are consumed as literal code points, unlike custom identifiers, which allow escapes.
+fn data_type_name(value: &ComponentValue) -> Option<&[u16]> {
+ if value.original_source_text.iter().any(|unit| unit == u16::from(b'\\')) {
+ return None;
+ }
+ value.ident()
+}
+
fn parse_single_component(
values: &[ComponentValue],
position: &mut usize,
@@ -179,7 +188,7 @@ fn parse_single_component(
if values.get(*position).is_some_and(|value| value.is_delim(b'<')) {
*position += 1;
- let name = values.get(*position).and_then(ComponentValue::ident);
+ let name = values.get(*position).and_then(data_type_name);
*position += usize::from(name.is_some());
if let Some(name) = name
&& values.get(*position).is_some_and(|value| value.is_delim(b'>'))
@@ -205,7 +214,7 @@ fn parse_component(
if values.get(*position).is_some_and(|value| value.is_delim(b'<'))
&& values
.get(*position + 1)
- .and_then(ComponentValue::ident)
+ .and_then(data_type_name)
.is_some_and(|name| equals_ascii(name, b"transform-list"))
&& values.get(*position + 2).is_some_and(|value| value.is_delim(b'>'))
{
diff --git a/Tests/LibWeb/Text/expected/css/property-syntax-escaped-type-names.txt b/Tests/LibWeb/Text/expected/css/property-syntax-escaped-type-names.txt
new file mode 100644
index 00000000000..175f92a6da4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/property-syntax-escaped-type-names.txt
@@ -0,0 +1,4 @@
+literal transform-list: accepted
+escaped transform-list start: SyntaxError
+escaped transform-list middle: SyntaxError
+escaped custom identifier: accepted
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/register-property-syntax-parsing.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/register-property-syntax-parsing.txt
index 5b763d60601..f6bc3fe608c 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/register-property-syntax-parsing.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/register-property-syntax-parsing.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 244 tests
-243 Pass
-1 Fail
+244 Pass
Pass syntax:'--foo', initialValue:'--foo' is valid
Pass syntax:'--foo | <color>', initialValue:'--foo' is valid
Pass syntax:'--foo | <color>', initialValue:'red' is valid
@@ -138,7 +137,7 @@ Pass syntax:'\1F914 hmm', initialValue:'🤔hmm' is valid
Pass syntax:'\1F914\1F914', initialValue:'🤔🤔' is valid
Pass syntax:'<color>#', initialValue:'yellow blue' is invalid
Pass syntax:'banana,nya', initialValue:'banana' is invalid
-Fail syntax:'<\6c ength>', initialValue:'10px' is invalid
+Pass syntax:'<\6c ength>', initialValue:'10px' is invalid
Pass syntax:'<banana>', initialValue:'banana' is invalid
Pass syntax:'<Number>', initialValue:'10' is invalid
Pass syntax:'<length', initialValue:'10px' is invalid
diff --git a/Tests/LibWeb/Text/input/css/property-syntax-escaped-type-names.html b/Tests/LibWeb/Text/input/css/property-syntax-escaped-type-names.html
new file mode 100644
index 00000000000..f99720d3fa8
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/property-syntax-escaped-type-names.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ const cases = [
+ ["literal transform-list", "<transform-list>", "translateX(0px)"],
+ ["escaped transform-list start", String.raw`<\74 ransform-list>`, "translateX(0px)"],
+ ["escaped transform-list middle", String.raw`<transform\2d list>`, "translateX(0px)"],
+ ["escaped custom identifier", String.raw`\66 oo`, "foo"],
+ ];
+ for (const [index, [label, syntax, initialValue]] of cases.entries()) {
+ try {
+ CSS.registerProperty({ name: `--escaped-type-${index}`, syntax, initialValue, inherits: false });
+ println(`${label}: accepted`);
+ } catch (error) {
+ println(`${label}: ${error.name}`);
+ }
+ }
+ });
+</script>