fix(ipc-types): refuse fetch hosts with a hexadecimal last label

URL parsing reads a last label such as 0x1 as a number, so a grant for
example.0x1 could never match a request.
This commit is contained in:
Marco Allegretti 2026-10-09 08:27:44 +00:00
parent 51ca194acb
commit a66e73d564
No known key found for this signature in database

View file

@ -104,11 +104,15 @@ impl fmt::Display for Capability {
/// A host in the canonical form URL parsing produces, so that a grant can /// A host in the canonical form URL parsing produces, so that a grant can
/// be compared with a request's host as a string: a lowercase DNS name of /// be compared with a request's host as a string: a lowercase DNS name of
/// 1–63 character labels of letters, digits and inner hyphens (at most 253 /// 1–63 character labels of letters, digits and inner hyphens (at most 253
/// characters) whose last label is not numeric, or an IPv4 address in /// characters) whose last label is neither numeric nor `0x`-prefixed, or an IPv4 address in
/// dotted-decimal form without leading zeros. IPv6 literals are not /// dotted-decimal form without leading zeros. IPv6 literals are not
/// supported. /// supported.
fn is_host_name(host: &str) -> bool { fn is_host_name(host: &str) -> bool {
let labels: Vec<&str> = host.split('.').collect(); let labels: Vec<&str> = host.split('.').collect();
// URL parsing reads a last label of `0x…` as a hexadecimal number.
if labels.last().is_some_and(|last| last.starts_with("0x")) {
return false;
}
if labels if labels
.last() .last()
.is_some_and(|last| !last.is_empty() && last.bytes().all(|b| b.is_ascii_digit())) .is_some_and(|last| !last.is_empty() && last.bytes().all(|b| b.is_ascii_digit()))
@ -182,6 +186,7 @@ mod tests {
"net:fetch:1.2.3", "net:fetch:1.2.3",
"net:fetch:example.123", "net:fetch:example.123",
"net:fetch:[::1]", "net:fetch:[::1]",
"net:fetch:example.0x1",
"sys:clipboard", "sys:clipboard",
] { ] {
assert!(text.parse::<Capability>().is_err(), "{text:?} accepted"); assert!(text.parse::<Capability>().is_err(), "{text:?} accepted");