Skip to content

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

test(agent): add test for sanitize redacting unparseable URLs

Steven Enamakeldee86dea0c5f
diff --git a/src/embed/agent_tests.rs b/src/embed/agent_tests.rs
index 76ceb0f9e6..dfa9cebc23 100644
--- a/src/embed/agent_tests.rs
+++ b/src/embed/agent_tests.rs
@@ -144,3 +144,17 @@ fn insecure_route_error_names_the_redacted_endpoint() {
);
assert!(msg.contains("api.example"), "origin stays readable: {msg}");
}
+
+#[test]
+fn sanitize_redacts_unparseable_urls() {
+ // A value that does not parse as an absolute URL cannot be proven free of
+ // credential-bearing components (e.g. protocol-relative userinfo), so it
+ // must never be echoed verbatim into diagnostics.
+ assert_eq!(sanitize_url_for_display("//user:sk-secret@host/path"), "<redacted>");
+ assert_eq!(sanitize_url_for_display("not a url at all"), "<redacted>");
+ // A parseable absolute URL is normalized, not dropped.
+ let normalized = sanitize_url_for_display("https://user:[email protected]/v1?k=leaky");
+ assert!(normalized.contains("api.example"));
+ assert!(!normalized.contains("sk-secret"));
+ assert!(!normalized.contains("leaky"));
+}