Skip to content

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

test(web-chat): a key echoed in a provider error never reaches the chat copy

M3gA-Mind10b2178c1c8e
diff --git a/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs
index d3c88008bb..a16d0b58e4 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs
@@ -502,3 +502,32 @@ fn chat_error_event_serializes_copy_key_and_params_to_literal_json() {
let bare = serde_json::to_value(WebChannelEvent::default()).expect("serializes");
assert!(bare.get("copy_key").is_none() && bare.get("copy_params").is_none());
}
+
+#[test]
+fn a_key_echoed_in_provider_detail_never_reaches_the_copy() {
+ // A rejected request's provider detail is quoted into the user-facing
+ // message and sent as a copy param; a provider may echo the key in it.
+ for key in [
+ "sk-proj-AbCdEf0123456789AbCdEf0123456789",
+ "sk-ant-api03-AbCdEf0123456789AbCdEf0123456789",
+ ] {
+ let got = classify_inference_error(&format!(
+ r#"someprovider API error (422 Unprocessable Entity): {{"error":{{"message":"bad parameter for key {key}"}}}}"#
+ ));
+ assert!(
+ got.message.contains("bad parameter"),
+ "the provider detail must still be quoted: {}",
+ got.message
+ );
+ assert!(
+ !got.message.contains("AbCdEf0123456789"),
+ "key leaked into the message: {}",
+ got.message
+ );
+ let params = got.copy_params.map(|p| p.to_string()).unwrap_or_default();
+ assert!(
+ !params.contains("AbCdEf0123456789"),
+ "key leaked into the copy params: {params}"
+ );
+ }
+}