Skip to content

Commit a24fdb5

Browse files
O V E R T R U EO V E R T R U E
authored andcommitted
fix: reject alias endpoints with path components
1 parent fe06d34 commit a24fdb5

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

crates/core/src/alias.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ fn validate_http_endpoint_url(url: &Url, label: &str) -> Result<()> {
387387
return Err(Error::Config(format!("{label} must include a host")));
388388
}
389389

390+
if !matches!(url.path(), "" | "/") || url.query().is_some() || url.fragment().is_some() {
391+
return Err(Error::Config(format!(
392+
"{label} must not include a path, query, or fragment"
393+
)));
394+
}
395+
390396
Ok(())
391397
}
392398

@@ -675,6 +681,25 @@ mod tests {
675681
);
676682
}
677683

684+
#[test]
685+
fn test_validate_alias_endpoint_rejects_path_query_and_fragment() {
686+
for endpoint in [
687+
"http://localhost:9000/api",
688+
"http://localhost:9000?region=us-east-1",
689+
"http://localhost:9000#alias",
690+
] {
691+
let result = validate_alias_endpoint(endpoint);
692+
693+
assert!(result.is_err(), "endpoint should be rejected: {endpoint}");
694+
assert!(
695+
result
696+
.unwrap_err()
697+
.to_string()
698+
.contains("Endpoint must not include a path, query, or fragment")
699+
);
700+
}
701+
}
702+
678703
#[test]
679704
fn test_validate_alias_endpoint_accepts_http_url_with_host() {
680705
validate_alias_endpoint("http://localhost:9000").unwrap();

0 commit comments

Comments
 (0)