mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
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:
parent
51ca194acb
commit
a66e73d564
1 changed files with 6 additions and 1 deletions
|
|
@ -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");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue