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
25 changes: 25 additions & 0 deletions crates/core/src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ fn validate_http_endpoint_url(url: &Url, label: &str) -> Result<()> {
return Err(Error::Config(format!("{label} must include a host")));
}

if !matches!(url.path(), "" | "/") || url.query().is_some() || url.fragment().is_some() {
return Err(Error::Config(format!(
"{label} must not include a non-root path, query, or fragment"
)));
}
Comment thread
overtrue marked this conversation as resolved.

Ok(())
}

Expand Down Expand Up @@ -675,6 +681,25 @@ mod tests {
);
}

#[test]
fn test_validate_alias_endpoint_rejects_path_query_and_fragment() {
for endpoint in [
"http://localhost:9000/api",
"http://localhost:9000?region=us-east-1",
"http://localhost:9000#alias",
] {
let result = validate_alias_endpoint(endpoint);

assert!(result.is_err(), "endpoint should be rejected: {endpoint}");
assert!(
result
.unwrap_err()
.to_string()
.contains("Endpoint must not include a non-root path, query, or fragment")
);
Comment thread
overtrue marked this conversation as resolved.
}
}

#[test]
fn test_validate_alias_endpoint_accepts_http_url_with_host() {
validate_alias_endpoint("http://localhost:9000").unwrap();
Expand Down
Loading