Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(embeddings): validate custom endpoint scheme before credential check

Steven Enamakela01e5224bd85
diff --git a/src/openhuman/inference/embeddings/factory.rs b/src/openhuman/inference/embeddings/factory.rs
index 6cb595f492..6ed86ba4cc 100644
--- a/src/openhuman/inference/embeddings/factory.rs
+++ b/src/openhuman/inference/embeddings/factory.rs
@@ -177,9 +177,13 @@ fn validate_custom_endpoint(endpoint: &str, has_credentials: bool) -> anyhow::Re
anyhow::bail!("custom embedding provider endpoint must not be empty");
}
+ let parsed = reqwest::Url::parse(endpoint)
+ .map_err(|_| anyhow::anyhow!("custom embedding provider endpoint is invalid"))?;
+ if !matches!(parsed.scheme(), "http" | "https") {
+ anyhow::bail!("custom embedding provider endpoint must use HTTP or HTTPS");
+ }
+
if has_credentials {
- let parsed = reqwest::Url::parse(endpoint)
- .map_err(|_| anyhow::anyhow!("custom embedding provider endpoint is invalid"))?;
let loopback = parsed
.host()
.map(|host| match host {
diff --git a/src/openhuman/inference/embeddings/factory_tests.rs b/src/openhuman/inference/embeddings/factory_tests.rs
index 95f4613857..d40ef26c79 100644
--- a/src/openhuman/inference/embeddings/factory_tests.rs
+++ b/src/openhuman/inference/embeddings/factory_tests.rs
@@ -227,6 +227,9 @@ fn default_embedder_falls_back_to_cloud_when_configured_provider_fails() {
#[test]
fn custom_endpoint_validation_rejects_blank_and_credentialed_remote_http() {
assert!(validate_custom_endpoint(" ", false).is_err());
+ assert!(validate_custom_endpoint("not-a-url", false).is_err());
+ assert!(validate_custom_endpoint("ftp://embedding.example", false).is_err());
+ assert!(validate_custom_endpoint("http://embedding.example", false).is_ok());
assert!(validate_custom_endpoint("http://embedding.example", true).is_err());
assert!(validate_custom_endpoint("http://localhost:1234/", true).is_ok());
assert_eq!(