Skip to content

Media attachments: images, audio and video from a machine's outbox - #5

Merged
skmp merged 21 commits into
mainfrom
skmp/media-attachments
Nov 27, 2026
Merged

skmp merged 21 commits into
mainfrom
skmp/media-attachments

Conversation

@skmp

@skmp skmp commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Attachments flow from a machine to the owner in the Claude app ("show me the screenshot from carbi"). The reverse direction (phone to machine) is out of scope: the app's model cannot pass an uploaded file's bytes into a tool.

  • Opt-in twice: hub machine flag allowAttachments and dispatcher --allow-attachments (dispatcher 0.7.0). Outbox --outbox, default ~/.local/share/switchboard/outbox; only regular files directly in it (O_NOFOLLOW, one link, no symlinks, FIFOs, subdirectories or dot files; the outbox must be the user's and not group/other writable).
  • Media only, by bytes: extension, magic and a full container walk must agree, nothing after the container's end, element lengths checked. PNG, JPEG, GIF, simple WebP, MP3, WAV, Ogg (Opus/Vorbis/FLAC), FLAC, M4A, MP4, MOV, WebM. Everything else (SVG, HTML, PDF, text, archives, extended WebP, MKV, ...) is refused. Metadata stripped where safe (JPEG EXIF/GPS/XMP, PNG text and eXIf, GIF comments, ID3, WAV LIST, FLAC tags, MP4 udta/meta incl. phone GPS).
  • Hub re-validates everything a machine sends (a lying dispatcher is refused and audited), keeps nothing on disk, rate limits (20 per machine per 10 min, 256 MiB per hour), audit line per fetch without content.
  • Tools: remote_attachments, remote_attachment (ImageContent / AudioContent / EmbeddedResource blob for video). Caps: image 3.75 MB (fits Claude's 5 MB image limit as base64), audio 8 MiB, video 16 MiB, chunked over both transports.
  • Review: a security red team (three rounds: polyglots, length games, metadata channels; the last WebP finding closed by accepting simple WebP only), correctness, MCP contract and docs. Residual channels (bytes inside codec data, Ogg/WebM tags, a prompt-injected session copying a sensitive screenshot into the outbox) are listed in docs/SWITCHBOARD.md.

Checks on the rebased branch: pytest 1980 passed / 9 skipped, ruff, ruff format, mypy --strict clean.

Only the owner can verify in the real app: whether voice mode shows images, plays audio, handles an embedded video blob, and accepts multi-MB results (DESIGN.md, "To verify with the real app").

After merge: update the hub, then add --allow-attachments to each machine's connector line and allowAttachments to its hub entry.

Follow-up on this branch (owner: MKV for video, 250 MB limit):

  • MKV (video/x-matroska) with a Matroska schema walk: Attachments elements, subtitle/metadata tracks, unknown codecs and content encodings refused; Tags, Chapters and text fields blanked; checked with real ffmpeg x264+AAC (OBS-like), x264+FLAC and VP9+Opus files that still decode after cleaning.
  • Video cap 250,000,000 bytes; hourly limit 1 GiB. Videos over 16 MiB get a one-time link <publicUrl>/attachments/<token> (256-bit token, memory only, 10 minutes, Range support, nosniff, CSP sandbox, no-store, 404 + per-IP rate limit for misses, at most 8x the file served). 250 MB over the agent transport: about 6 s to the link, peak memory about 2x the file on each side.
  • Merged with main (incident log, Incident log: what failed, where, when and why #6): dispatcher and connector 0.9.0 carry attachments and health together. Full suite on the merge: 2123 passed, 9 skipped.

🤖 Generated with Claude Code

https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh

skmp and others added 14 commits November 27, 2026 09:58
New verbs `attachments` (list) and `attachment <name>` (one file, streamed
in 1 MiB base64 chunks so it fits the agent transport's 5 MiB frames),
only with the new policy option --allow-attachments; --outbox replaces the
default ~/.local/share/switchboard/outbox, which nobody creates.

Only regular files directly in the outbox (O_NOFOLLOW, fstat, one link),
only whole images, audio and video: extension, magic bytes and a walk of
the whole container must agree, nothing may follow the container's end.
PNG, JPEG, GIF, WebP, MP3, WAV, Ogg, FLAC, M4A, MP4, MOV and WebM; SVG,
HTML, PDF, text, archives and programs never pass. EXIF/GPS, XMP, IPTC,
PNG text, ID3, WAV and FLAC tags and MP4 udta/meta are stripped from the
copy that is sent. Caps: images 3,750,000 bytes (5 MB as base64), audio
8 MiB, video 16 MiB.

protocol.py parses both answers strictly (chunk order and sizes,
SHA-256, the hub's own caps). The connector's version moves with the
dispatcher's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
The machine flag allowAttachments (default false) is the hub's half of
the opt-in; the local transport passes --allow-attachments, agent hellos
may carry allowAttachments (accepted as optional, disagreements shown in
status), remote-check and status say "attachments allowed" or "off".

remote_attachments lists the outbox for voice (count, newest kind and
age, names framed as the machine's). remote_attachment fetches one file
(the newest, or by spoken name), runs dispatcher.media_check again on the
received bytes, requires the announced kind, type and name, and returns
ImageContent, AudioContent, or for video an EmbeddedResource with a blob.
Both read-only, offered only when a machine allows attachments. Limits
per machine and in total, nothing on disk, an audit line per fetch with
the name as HMAC and no content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
SWITCHBOARD.md gets the Attachments section (direction and why the
reverse is out of scope, opt-ins, outbox rules, formats and checks,
metadata stripped and not, sizes and chunking, hub re-validation,
limits, audit, tools and content types), the new verbs and error codes,
serve-mode notes and threat model rows. DESIGN.md records the decision
and what only the owner can verify in the Claude app. REFERENCE.md,
SETUP-WSL.md, SETUP-AGENTS.md, the example configs and the connector
unit name the new flag and option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
Red-team review fixes for media_check (also run by the hub):
- MP4/MOV/M4A: moov needs mvhd and a track with a vide or soun handler,
  and an mdat must exist; only known boxes in the walked containers;
  free, skip, wide and uuid are zeroed like udta and meta; size 0 only
  for mdat; audio or video is decided by the tracks, so an Apple .m4v
  listing M4A is a video and a generic-brand audio file is an .m4a.
- WebM: at least one TrackEntry; Void, Tags and Chapters become zeroed
  Voids; every cluster and the EBML header are walked by known IDs.
- PNG keeps only PNG_KEEP chunks and inflates IDAT and APNG fdAT data to
  exactly the scanlines; JPEG keeps standard segments and JFIF, ICC and
  Adobe APP segments, refuses unknown markers and rebuilds an EXIF
  segment holding only the orientation; WAV keeps five chunk types; GIF
  drops plain text; Ogg allows one logical stream.
- Images over 8000 pixels a side are refused.
- MAX_MEDIA_ELEMENTS bounds every walk; the FLAC last-frame search has a
  CRC budget and looks only at the last 1 MiB.

Each red-team attack is a regression test, with timing tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
…every attempt

media_check runs in asyncio.to_thread. remote_attachment allows one
fetch at a time hub-wide. FetchLimiter reserves the fetch and its listed
size before the machine is asked and corrects the size to the bytes
received, so refused, failed and rejected fetches count too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
…mits

Drop the claim that no polyglot can reach the client: payloads inside
media data cannot be excluded without re-encoding. Record the allowlist
decision, the orientation rebuild, the 8000 pixel limit, the element
budget, the worker thread and the attempt counting; add the large audio
and video result check to the verify list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
An allowlisted chunk, box or segment name accepted any length, so a ZIP
still rode in a PNG gAMA/pHYs/tRNS/iCCP chunk, a WAV smpl chunk or an MP4
handler name, and payloads survived after the fixed fields of mvhd, fmt,
JFIF, Adobe, ICC, GCE and NETSCAPE2.0.

- PNG: exact lengths (PNG_LENGTHS, by color type for sBIT, bKGD, tRNS,
  PLTE), each kept chunk once and before IDAT, iCCP a whole ICC profile.
- JPEG: standard segment lengths by their fields; JFIF cut to 14 bytes
  (thumbnail dropped), JFXX dropped, Adobe exactly 12 bytes, ICC parts
  must join to one whole profile or are dropped.
- GIF: control and looping extensions exactly one fixed sub-block.
- WAV: only fmt (16, 18 or 40 bytes), fact (4) and data, once each; cue
  and smpl dropped; pad byte zeroed.
- MP4: leaf boxes by version, flags and entry count; handler names
  capped and zeroed; header times zeroed; boxes not needed for playback
  zeroed; the deciding track needs stsd, sample sizes, chunk offsets and
  samples.
- WebM: a TrackEntry with TrackType 1 (video) is required.

Regression tests for each red-team attack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
SWITCHBOARD.md names every channel that stays open (media data, palettes,
ICC profile contents, fixed-size numeric fields, undecoded MP4 and WebM
structures, Ogg comments) instead of implying the allowlists close them;
format table, metadata section, threat model and DESIGN.md decision
updated; dispatcher line count in the setup guides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
The round-3 red team smuggled ZIP data in a last ANIM or ALPH chunk, bytes after a VP8X header and EXIF inside an ANMF frame. A WebP is now exactly one VP8 or VP8L chunk covering the file; the extended format is refused as a whole, and a simple WebP has no metadata to strip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
The owner asked for .mkv (OBS's default). An .mkv must carry the EBML
DocType "matroska" and a .webm "webm". SeekHead, Info, Tracks and Cues
are now walked by a schema for both: every child listed, every number of
its type's length, only video and audio tracks with allowlisted codecs,
no Attachments, content encodings or other private structures. Titles,
applications, dates and track names are blanked to Void and CRC-32
elements over a blanked range are recomputed. Info and Tracks appear
once. The element budget grows by one per KiB of the file.

The large validators return their bytearray instead of copying it again,
and the dispatcher streams chunks from a memoryview, which bounds a video
to about twice its size in memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
The owner set the video limit to 250 MB; the cap is 250,000,000 bytes
(decimal, as he said it) on dispatcher and hub. Audio and image caps
stay. The hub's hourly byte limit grows to 1 GiB, four such videos.

The hub no longer collects the base64 answer: AttachmentStream decodes
each chunk document as its ssh line or agent frame arrives into one
buffer of the announced size and hashes it, so a 250 MB video needs
about its own size while it arrives. The response cap of the verb
follows the largest cap, and each line is bounded on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
A valid live MKV of any size is a short head and a hole, so the cap is
tested at 250,000,000 and 250,000,001 bytes without a fixture: the one
at the cap is listed, read, walked and decoded chunk by chunk, the one
over it is refused from its size before reading, and the hub refuses
an announced size over the cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
A 250 MB video does not fit an MCP tool result. A video over 16 MiB
(the embedded limit, the old cap) is held by the hub as its own cleaned
copy in memory only, under a 256-bit random token, for 10 minutes, and
served at <publicUrl>/attachments/<token>: GET and HEAD, one byte range
(206, 416 past the end), nosniff, no-store, no-referrer, a sandbox CSP,
inline with the plain file name. Lookup is by the token's hash; all
links hold at most 512 MiB (oldest dropped) and each serves at most 8
times its size. Misses are 404 and rate limited per IP like /authorize;
the request log shows only the token's fingerprint.

The fetch of such a video runs on in the background for up to 600 s,
holding the one fetch slot; a call that ends first says it is still
coming, and the next call for that file waits for the same fetch and
gets the link. The same file asked again gets the same link. Audit:
the fetch as outcome link, plus attachment_link lines when a link is
created and when it ends, with requests, ranges and bytes served.

Spoken sizes are decimal now, so the cap is said as 250.0 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
SWITCHBOARD.md gets "Large videos: a link" (token, headers, ranges,
limits, the background fetch, audit, proxy, measured memory and time),
the link in the threat model and the residual-channel list, and the
owner's follow-up with its tests. DESIGN.md records the decision and
what to verify in the app (opening the link, MKV on phones, seeking).
REFERENCE.md lists the endpoint. The Caddyfile example's optional IP
restriction exempts /attachments/*.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
skmp and others added 4 commits November 27, 2026 15:09
A SeekHead entry could point into a SimpleBlock's frame data, where a
hidden Attachments, Tags, Chapters or second Tracks element is read by
players that follow seek pointers (ffmpeg, so Chrome, mpv and VLC). Now
every Seek entry must name the id and segment offset of a top-level
element the walk visited (entries for blanked Tags and Chapters are
blanked), every cue a walked cluster and a block in it, and a cue may
not name a codec state. Block groups are walked (block additions, codec
states and slices refused), EncryptedBlock is refused.

Also: TrackType is read as a number (01 00 is 256, not video), EBML
header children appear once with bounded lengths (two DocTypes are
refused), and nested CRC-32 values are recomputed innermost first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
…e slot release

The fetch slot went to the background fetch only after the call's wait,
so a cancelled call released it and the fetch's done callback released
it again (the counter stayed at -1: two 250 MB fetches could run). The
slot is now handed over before the wait and released exactly once.

A finished background fetch is forgotten when it ends, so a later
request no longer replays a link that has expired or been evicted.

The served budget was charged for the whole requested range up front,
so a player seeking with bytes=N- lost its link after about 8 seeks. It
is now charged per 1 MiB slice as it is sent; a response stops when the
client disconnects, the link ends or the budget runs out, and no
response keeps an ended link's bytes alive.

Docs: the Matroska pointer checks, residual channels, the link's budget,
slow readers and memory, and the review notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
libavformat resyncs after a parse error in the header by scanning raw
bytes for a top-level id. A Language padded with NULs past 16 MiB made
Tracks fail to parse, and the scan found an Attachments element hidden
in a kept CodecPrivate. Now a Language element over 32 bytes is blanked,
a CodecPrivate holding any top-level id is refused, and the cleaned copy
may hold no top-level id before the first Cluster except at a walked
element's start or as a SeekID. Tests cover the attack, every id in
CodecPrivate, the Language bound, an id in a TrackUID and an ffprobe
check of the attack and of the cleaned copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
skmp and others added 3 commits November 27, 2026 15:49
…ekID

libavformat's first resync starts one byte after the Segment element's
start, so the top-level id scan now starts there: a 4-byte Segment size
can spell a level-1 id (19 41 A4 69, Attachments, is 155,296,873 bytes).
Every SeekID must be followed directly by its SeekPosition, which bounds
the fake element a resync on a SeekID value would read to 5,036 bytes.
Docstrings now say the scan narrows resync landing spots; the guarantee
is that no kept element fails to parse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
A SeekID value stays a resync landing spot whose fake element can reach
frame data; the guarantee before the first Cluster is that no kept
element fails to parse in libavformat (ffmpeg 6.1). Records the round 5
hardening in SWITCHBOARD.md and DESIGN.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
# Conflicts:
#	deploy/remote/switchboard-connect
#	deploy/remote/switchboard-remote
#	docs/REFERENCE.md
#	docs/SWITCHBOARD.md
#	src/voice_coding_mcp/mcp.py
#	src/voice_coding_mcp/remote/agents.py
#	src/voice_coding_mcp/remote/connector.py
#	src/voice_coding_mcp/remote/dispatcher.py
#	src/voice_coding_mcp/remote/protocol.py
#	tests/remote/test_cli_remote.py
#	tests/remote/test_dispatcher.py
#	tests/remote/test_dispatcher_keys.py
#	tests/remote/test_transport.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant