The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(voiceNotes): validate typed voice notes by opaque reference
Steven Enamakel0688e85b3e9d
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsxindex 0c6740e0f9..c34615f322 100644--- a/app/src/features/conversations/Conversations.tsx+++ b/app/src/features/conversations/Conversations.tsx@@ -1510,6 +1510,7 @@ const Conversations = ({const { mime } = await storeVoiceNote(noteId, draft.blob);const voicePart = await voiceNoteContentPart(noteId,+ mime,draft.blob,draft.durationMs,draft.waveformdiff --git a/app/src/features/voiceNotes/voiceNoteApi.test.ts b/app/src/features/voiceNotes/voiceNoteApi.test.tsindex 79dc069e17..94cfab6bb0 100644--- a/app/src/features/voiceNotes/voiceNoteApi.test.ts+++ b/app/src/features/voiceNotes/voiceNoteApi.test.ts@@ -26,6 +26,7 @@ describe('voiceNoteApi', () => {it('keeps a recording as a typed voice-note part with its media and duration', async () => {const part = await voiceNoteContentPart('note-123',+ 'audio/wav',new Blob([new Uint8Array([0, 1, 2])], { type: 'audio/wav' }),5000,[0.2, 0.8]@@ -40,7 +41,6 @@ describe('voiceNoteApi', () => {pushToTalk: false,media: {opaqueId: 'note-123',- url: 'data:audio/wav;base64,AAEC',kind: 'audio',contentType: 'audio/wav',codec: 'audio/wav',diff --git a/app/src/features/voiceNotes/voiceNoteApi.ts b/app/src/features/voiceNotes/voiceNoteApi.tsindex 8c2a381080..0a4b5256d8 100644--- a/app/src/features/voiceNotes/voiceNoteApi.ts+++ b/app/src/features/voiceNotes/voiceNoteApi.ts@@ -51,27 +51,26 @@ export function bytesToBase64(bytes: Uint8Array): string {/** Keep the recorded media on the typed web-chat wire beside its transcript. */export async function voiceNoteContentPart(noteId: string,+ mime: string,blob: Blob,durationMs: number,waveform: number[]): Promise<ContentPart> {- const bytes = new Uint8Array(await blob.arrayBuffer());- const mime = blob.type || 'audio/webm';+ const contentType = mime || blob.type || 'audio/webm';return {kind: 'voice_note',voiceNote: {- codec: mime,+ codec: contentType,durationMs,waveform,pushToTalk: false,media: {opaqueId: noteId,- url: `data:${mime};base64,${bytesToBase64(bytes)}`,kind: 'audio',- contentType: mime,- codec: mime,+ contentType,+ codec: contentType,durationMs,- sizeBytes: bytes.length,+ sizeBytes: blob.size,},},};diff --git a/crates/openhuman-core/src/agent/attachments/parts.rs b/crates/openhuman-core/src/agent/attachments/parts.rsindex f98a0eaf1e..37f7e2f4cb 100644--- a/crates/openhuman-core/src/agent/attachments/parts.rs+++ b/crates/openhuman-core/src/agent/attachments/parts.rs@@ -115,9 +115,9 @@ pub fn fold_into_message(text: &str, parts: &[ContentPart]) -> Result<String, Atmarkers.push(format!("[FILE:{}]", source_of(media, index)?));}ContentPart::VoiceNote { voice_note } => {- // The audio already has a durable voice-note sidecar. Validate- // the typed wire reference, but never splice it into model text.- source_of(&voice_note.media, index)?;+ // The handler validates this opaque reference against the+ // durable note store. Never expose it in model-visible text.+ let _ = voice_note;}other => {return Err(AttachmentPartError::UnsupportedKind {diff --git a/crates/openhuman-core/src/agent/attachments/parts_tests.rs b/crates/openhuman-core/src/agent/attachments/parts_tests.rsindex c7eadfaa30..b77bd43abb 100644--- a/crates/openhuman-core/src/agent/attachments/parts_tests.rs+++ b/crates/openhuman-core/src/agent/attachments/parts_tests.rs@@ -77,7 +77,12 @@ fn video_and_audio_ride_the_file_marker() {fn typed_voice_notes_keep_audio_out_of_model_text() {let part = ContentPart::VoiceNote {voice_note: tinychannels_bus::VoiceNote {- media: media("data:audio/wav;base64,AAA"),+ media: MediaReference {+ opaque_id: Some("note-typed".into()),+ content_type: Some("audio/wav".into()),+ kind: MediaKind::Audio,+ ..Default::default()+ },duration_ms: Some(5000),..Default::default()},diff --git a/crates/openhuman-core/src/web_chat/voice_notes.rs b/crates/openhuman-core/src/web_chat/voice_notes.rsindex 8b86986a83..049baaedf1 100644--- a/crates/openhuman-core/src/web_chat/voice_notes.rs+++ b/crates/openhuman-core/src/web_chat/voice_notes.rs@@ -132,8 +132,8 @@ pub(crate) fn read_note(/// Ensure a typed chat attachment names and carries the already stored note./// The RPC upload happens before chat submission; this comparison binds the-/// following typed part to those durable bytes instead of treating it as a-/// disposable or model-visible attachment marker.+/// following typed part to those durable bytes instead of resending audio or+/// treating the opaque reference as model-visible attachment text.pub(crate) fn validate_typed_media(workspace: &Path,note_id: &str,@@ -142,31 +142,19 @@ pub(crate) fn validate_typed_media(if !is_valid_note_id(note_id) || media.opaque_id.as_deref() != Some(note_id) {return Err("voice note media must name its stored note id".into());}- let url = media- .url- .as_deref()- .ok_or_else(|| "voice note media needs an inline data: URL".to_string())?;- let (header, encoded) = url- .strip_prefix("data:")- .and_then(|data| data.split_once(','))- .ok_or_else(|| "voice note media needs an inline data: URL".to_string())?;- let mime = header- .strip_suffix(";base64")- .ok_or_else(|| "voice note media must use base64 encoding".to_string())?;- use base64::Engine as _;- let bytes = base64::engine::general_purpose::STANDARD- .decode(encoded)- .map_err(|error| format!("voice note media has invalid base64: {error}"))?;- let (stored, stored_mime) = read_note(workspace, note_id)?+ if media.url.is_some() || media.path.is_some() || media.local_cache_path.is_some() {+ return Err("typed voice note must use its opaque stored-media reference".into());+ }+ if media.kind != tinychannels_bus::MediaKind::Audio {+ return Err("typed voice note reference must have audio kind".into());+ }+ let (_, stored_mime) = read_note(workspace, note_id)?.ok_or_else(|| "typed voice note has no stored audio".to_string())?;- let normalized_mime = mime.split(';').next().unwrap_or(mime).trim();- if normalized_mime != stored_mime- || media.content_type.as_deref().is_some_and(|content_type| {+ if media.content_type.as_deref().is_some_and(|content_type| {content_type.split(';').next().unwrap_or(content_type).trim() != stored_mime})- || bytes != stored{- return Err("typed voice note does not match the stored audio".into());+ return Err("typed voice note mime does not match the stored audio".into());}Ok(())}