Repository navigation
fix: support IPv6 URLs and reject invalid ports #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()?; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Accept valid IPvFuture literals as bracketed hosts in addition to IPv6 addresses. Prompt for AI agentsIn `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; | ||
| } | ||
|
|
@@ -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] | ||
|
|
||
There was a problem hiding this comment.
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, soparse_http_urlreturnsNone,is_urlroutes 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