Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ nzb-rs = "0.6"
# ── Feeds ──────────────────────────────────────────────────────────────────────
feed-rs = "2.3"

# ── URL parsing ───────────────────────────────────────────────────────────────
url = "2.5"

# ── CLI ───────────────────────────────────────────────────────────────────────
clap = { version = "4", features = ["derive"] }

Expand Down
1 change: 1 addition & 0 deletions crates/komide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tokio = { workspace = true }
feed-rs = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
url = { workspace = true }
uuid = { workspace = true }
jiff = { workspace = true }

Expand Down
18 changes: 12 additions & 6 deletions crates/komide/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,14 +572,20 @@ impl KomideService {
}
}

fn validate_url(url: &str) -> Result<(), KomideError> {
if url.is_empty() || (!url.starts_with("http://") && !url.starts_with("https://")) {
return InvalidUrlSnafu {
url: url.to_string(),
fn validate_url(input: &str) -> Result<(), KomideError> {
let parsed = url::Url::parse(input).map_err(|_| {
InvalidUrlSnafu {
url: input.to_string(),
}
.build()
})?;
match parsed.scheme() {
"http" | "https" if parsed.has_host() => Ok(()),
_ => InvalidUrlSnafu {
url: input.to_string(),
}
.fail();
.fail(),
}
Ok(())
}

async fn fetch_bytes(client: &reqwest::Client, url: &str) -> Result<Vec<u8>, KomideError> {
Expand Down
38 changes: 38 additions & 0 deletions crates/komide/src/service/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,44 @@ async fn validate_url_accepts_http() {
assert!(validate_url("http://example.com/feed.xml").is_ok());
}

#[tokio::test]
async fn validate_url_accepts_loopback_with_port() {
assert!(validate_url("http://127.0.0.1:7878").is_ok());
}

#[tokio::test]
async fn validate_url_accepts_lan_host() {
assert!(validate_url("http://kanon.lan").is_ok());
}

#[tokio::test]
async fn validate_url_rejects_javascript_scheme() {
assert!(validate_url("javascript:alert(1)").is_err());
}

#[tokio::test]
async fn validate_url_rejects_unparseable() {
assert!(validate_url("not a url").is_err());
}

#[tokio::test]
async fn validate_url_rejects_scheme_relative() {
// old prefix-match would accept this as invalid; url::Url rejects it outright
assert!(validate_url("//no-scheme.com").is_err());
}

#[tokio::test]
async fn validate_url_rejects_http_without_host() {
// old prefix-match silently accepted "http://"; url::Url parses but has no host
assert!(validate_url("http://").is_err());
}

#[tokio::test]
async fn validate_url_rejects_https_colon_only() {
// old prefix-match rejected; new parse rejects too (no host)
assert!(validate_url("https:").is_err());
}

#[tokio::test]
async fn list_feeds_empty_returns_empty() {
let (svc, _rx) = setup().await;
Expand Down
Loading