Skip to content

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

fix(channels): validate voice media payload size before storing

Steven Enamakel7a97638b2c27
diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback.rs b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
index 38750fb16e..f042fada71 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
@@ -18,6 +18,8 @@ use tokio::sync::mpsc;
const MAX_CALLBACK_BYTES: usize = 128 * 1024;
const MAX_TRANSCRIPTION_BYTES: usize = 12 * 1024 * 1024;
+const MAX_VOICE_MEDIA_BYTES: usize = 12 * 1024 * 1024;
+const MAX_VOICE_MEDIA_DECODED_BYTES: usize = 8 * 1024 * 1024;
const MAX_CONTROLLER_BYTES: usize = 1024 * 1024;
type ProgressiveChannelRegistry =
@@ -245,12 +247,22 @@ impl ChannelHostCallbacks {
&self,
request: tinychannels_bus::HostStoreVoiceMediaRequest,
) -> Result<tinychannels_bus::HostStoreVoiceMediaResult> {
- Self::validate_callback_size(&request)?;
+ if serde_json::to_vec(&request)
+ .map_or(true, |bytes| bytes.len() > MAX_VOICE_MEDIA_BYTES)
+ {
+ return Err(Error::failed("voice media callback exceeds its limit"));
+ }
+ let decoded = base64::Engine::decode(
+ &base64::engine::general_purpose::STANDARD,
+ &request.audio_base64,
+ )
+ .map_err(|_| Error::failed("voice media payload is invalid"))?;
+ if decoded.is_empty() || decoded.len() > MAX_VOICE_MEDIA_DECODED_BYTES {
+ return Err(Error::failed("voice media exceeds its size limit"));
+ }
let scope = &request.scope;
- let Some(channel) = self
- .context()?
- .channels_by_name
- .get(&scope.configured_instance)
+ let context = self.context()?;
+ let Some(channel) = context.channels_by_name.get(&scope.configured_instance)
else {
return Err(Error::failed("voice media account is not configured"));
};
diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
index 0e66c18d0f..3b47c9044d 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
@@ -220,7 +220,10 @@ async fn voice_media_projection_accepts_only_durable_refs_for_the_configured_acc
turn_id: "telegram_42_7".into(),
},
direction: tinychannels_bus::HostVoiceMediaDirection::Inbound,
- audio_base64: "fixture bytes are already stored by the module".into(),
+ audio_base64: base64::Engine::encode(
+ &base64::engine::general_purpose::STANDARD,
+ vec![7; 200 * 1024],
+ ),
mime_type: "audio/ogg".into(),
codec: Some("ogg_opus".into()),
duration_ms: Some(1000),
@@ -251,6 +254,13 @@ async fn voice_media_projection_accepts_only_durable_refs_for_the_configured_acc
let mut unscoped = request();
unscoped.media_reference.as_mut().unwrap().opaque_id = Some("external-id".into());
assert!(callback.store_voice_media(unscoped).await.is_err());
+
+ let mut oversized = request();
+ oversized.audio_base64 = base64::Engine::encode(
+ &base64::engine::general_purpose::STANDARD,
+ vec![7; 8 * 1024 * 1024 + 1],
+ );
+ assert!(callback.store_voice_media(oversized).await.is_err());
}
#[tokio::test]
diff --git a/tests/native_channel_session_restart_e2e.rs b/tests/native_channel_session_restart_e2e.rs
index d27de7f08e..53dbc0374c 100644
--- a/tests/native_channel_session_restart_e2e.rs
+++ b/tests/native_channel_session_restart_e2e.rs
@@ -742,6 +742,7 @@ async fn native_telegram_session_resumes_after_the_core_process_restarts() {
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+#[cfg(feature = "voice")]
async fn telegram_voice_note_runs_scoped_stt_agent_and_mirror_tts_through_modules() {
let tmp = tempfile::tempdir().expect("temporary core home");
let home = std::fs::canonicalize(tmp.path()).expect("canonicalize temporary home");