Skip to content
Merged
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
36 changes: 30 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,31 @@ pub fn parse_http_url(s: &str) -> Option<(String, String)> {
return None;
}
let authority = rest.split(['/', '?', '#']).next()?;
let host = authority
.rsplit('@')
.next()?
.split(':')
.next()?
.trim_matches(['[', ']']);
let host_port = authority.rsplit('@').next()?;
let host = if let Some(bracketed) = host_port.strip_prefix('[') {
let (host, suffix) = bracketed.split_once(']')?;
host.parse::<std::net::Ipv6Addr>().ok()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Scoped IPv6 URLs become local paths

When the input contains a valid percent-encoded IPv6 zone identifier, such as %25eth0, host.parse::<std::net::Ipv6Addr>() rejects the zone identifier, so parse_http_url returns None, is_url routes the source to the local-file path, and callers report a missing-file error instead of fetching audio.

Validate the IPv6 address separately from its encoded zone identifier and accept valid zone suffixes.

Prompt for AI agents
In `src/util.rs` at line 78:

**Scoped IPv6 URLs become local paths**

When the input contains a valid percent-encoded IPv6 zone identifier, such as `%25eth0`, `host.parse::<std::net::Ipv6Addr>()` rejects the zone identifier, so `parse_http_url` returns `None`, `is_url` routes the source to the local-file path, and callers report a missing-file error instead of fetching audio.

Validate the IPv6 address separately from its encoded zone identifier and accept valid zone suffixes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · IPvFuture URLs are rejected

When the source uses a valid IPvFuture literal, for example http://[v1.example]/audio.wav, host.parse::<std::net::Ipv6Addr>() rejects valid IPvFuture literals such as [v1.example], so parse_http_url returns None and callers treat the URL as a local path instead of a URL source.

Accept valid IPvFuture literals as bracketed hosts in addition to IPv6 addresses.

Prompt for AI agents
In `src/util.rs` at line 78:

**IPvFuture URLs are rejected**

When the source uses a valid IPvFuture literal, for example `http://[v1.example]/audio.wav`, `host.parse::<std::net::Ipv6Addr>()` rejects valid IPvFuture literals such as `[v1.example]`, so `parse_http_url` returns `None` and callers treat the URL as a local path instead of a URL source.

Accept valid IPvFuture literals as bracketed hosts in addition to IPv6 addresses.

if !suffix.is_empty() {
let port = suffix.strip_prefix(':')?;
if port.is_empty() || !port.bytes().all(|b| b.is_ascii_digit()) {
return None;
}
port.parse::<u16>().ok()?;
}
host
} else {
let (host, port) = match host_port.split_once(':') {
Some((host, port)) => (host, Some(port)),
None => (host_port, None),
};
if let Some(port) = port {
if port.is_empty() || !port.bytes().all(|b| b.is_ascii_digit()) {
return None;
}
port.parse::<u16>().ok()?;
}
host
};
if host.is_empty() || host.chars().any(|c| c.is_whitespace()) {
return None;
}
Expand Down Expand Up @@ -693,6 +712,11 @@ mod tests {
assert!(!is_url("http:// "));
assert!(is_url("https://example.com/a?b=c#d"));
assert!(is_url("http://user:pass@example.com:8080/a"));
assert!(is_url("http://[::1]/audio.wav"));
assert!(is_url("https://[2001:db8::1]:8443/audio.wav"));
assert!(!is_url("http://[not-ip]/audio.wav"));
assert!(!is_url("http://example.com:bad/audio.wav"));
assert!(!is_url("http://example.com:/audio.wav"));
}

#[test]
Expand Down