buzz icon indicating copy to clipboard operation
buzz copied to clipboard

`buzz messages send --file` embeds every non-video attachment as `![image](…)`, so documents arrive as broken images

Open ams1 opened this issue 2 months ago • 4 comments

Describe the bug

buzz messages send --file <path> builds the markdown embed from a two-way branch: video/* gets ![video](…), and everything else gets ![image](…). There is no branch for "not displayable inline".

crates/buzz-cli/src/commands/messages.rs:658-665 (on main @ b1f6b7ef7):

media_tags.push(crate::client::build_imeta_tag(&desc));
if desc.mime_type.starts_with("video/") {
    media_content.push_str("\n![video](");
} else {
    media_content.push_str("\n![image](");
}
media_content.push_str(&desc.url);
media_content.push(')');

So a .txt, .pdf, .md or .xlsx is announced to the client as an image. Buzz Desktop renders a broken-image placeholder, and clicking it opens the image viewer — empty, with a zoom bar under it. The file itself uploaded fine and the imeta tag is correct; only the message body is wrong.

This is not a client limitation. #6791 describes the intended baseline for these types as "a generic file card with a download button". The client can show that already — the CLI just talks it out of it by putting an image embed in the body.

Why "name it with the right extension" is not a workaround

The relay types a blob by sniffing content, not by filename (infer::get(), buzz-media/src/validation.rs). Plain text has no magic signature, so it is stored as application/octet-stream however the file is named. Measured on relay 0.2.1:

$ buzz upload file --file test-atasament.txt
{
  "url": "https://<relay>/media/e9cb2c16….bin",
  "size": 40,
  "type": "application/octet-stream"
}

The upload is .bin / application/octet-stream, and the branch above then sends it as ![image]. Every text document takes this path.

To Reproduce

  1. printf 'hello\n' > note.txt
  2. buzz messages send --channel <uuid> --file note.txt --content "test"
  3. Read the event back — the body ends with ![image](https://<relay>/media/<sha>.bin)
  4. Open the channel in Buzz Desktop: broken-image placeholder; clicking it opens an empty image viewer.

Expected behavior

Embed only what a client can display inline, and link the rest:

  • image/* → ![image](url)
  • video/* → ![video](url)
  • anything else → [<original filename>](url), which renders as a file card

Using the original filename also restores the one piece of information the sha-named URL destroys — [report.xlsx](…/9f3c….bin) tells the reader what they are opening.

Impact

This is the common case for non-interactive agents, which produce documents far more often than images. The failure is also misleading: it looks like a broken or inaccessible file, so the reflex is to check permissions or re-upload, when the bytes were never the problem.

Adjacent, already filed: #2963 / #3083 (the CLI's upload allowlist rejects the same documents earlier in the pipeline), #5149 and #3241 (/media/ URLs return 401 outside Desktop, so pasting a raw link is not an alternative), #6791 (rendering Markdown/HTML inline).

Environment

  • buzz CLI built from main
  • relay 0.2.1, self-hosted
  • Buzz Desktop 0.5.19, macOS arm64

ams1 avatar Sep 04 '26 11:09 ams1

The branch you point at is real, but I could not get a non-image to reach it — upload_file rejects those types earlier, so on origin/main (f038cbbb0) the else arm only ever sees images today.

Measured

Built the CLI from f038cbbb0 and sent both file types at a local relay:

$ buzz messages send --channel <uuid> --file note.txt --content "attachment test"
{"error":"error","message":"upload failed for /tmp/note.txt: unsupported file type: application/octet-stream","retryable":false}

$ buzz messages send --channel <uuid> --file spec.pdf --content "pdf test"
{"error":"error","message":"upload failed for /tmp/spec.pdf: unsupported file type: application/pdf","retryable":false}

Both stop at crates/buzz-cli/src/client.rs:1178, against the allowlist at client.rs:64:

const ALLOWED_MIMES: &[&str] = &[
    "image/jpeg", "image/png", "image/gif", "image/webp", "video/mp4",
];

video/mp4 takes the ![video] arm, so everything that can currently reach the else arm is image/jpeg|png|gif|webp — all of which ![image] labels correctly. The two-way branch is wrong in principle but not reachable yet.

Your buzz upload file output

buzz upload file and messages send --file both call the same client.upload_file (upload.rs:7, messages.rs:655), so they share that allowlist. A .txt returning application/octet-stream successfully should not be possible on this build — that check has been unchanged since d99ad131f (2026-06-10). Were you on a fork or an older CLI? That would explain the difference and is worth pinning down, because it changes whether this is reachable for anyone today.

Why this still matters, and the ordering

Not arguing the issue away — the branch should be fixed. But it is dead code until the allowlist widens, which is exactly what #2963 / #3083 ask for. If the embed fix lands first it changes nothing observable; if the allowlist widens first without it, every newly-allowed document immediately arrives as a broken image. The allowlist change is the one that needs this fix to land with it.

I have the embed change written and tested locally (image/* → ![image], video/* → ![video], everything else → [<file name>](url), with the label escaped so a ] in a name cannot truncate the link). Happy to open it whenever the allowlist side is decided — just did not want to send a fix for a path nothing can currently take.

PresentJay avatar Sep 05 '26 06:09 PresentJay

You're right, and it's worth stating plainly: on stock main this is not reproducible. The two bugs are stacked, and #2963 hides this one.

upload_file (crates/buzz-cli/src/client.rs) applies an image-only allowlist — image/jpeg, image/png, image/gif, image/webp, video/mp4 — and rejects everything else before a single byte is sent. Every type that survives that gate is displayable inline, so the else arm really does only ever see images today. That is exactly what you measured.

We hit the embed branch because we run a local patch that mirrors the relay's denylist (buzz-media/src/validation.rs::validate_file_content) instead of the CLI's allowlist — the same change #3083 proposes and #3060 / #4298 implement. Once a non-image can actually upload, it arrives as application/octet-stream (the relay types blobs by sniffing content, not filename, so a .txt is octet-stream however you name it), falls into the else, and every document is announced to the client as ![image](…).

So I'd frame this as latent, not invalid: whichever fix for #2963 lands first turns a hard failure ("unsupported file type", nothing uploaded) into a silent one — the file uploads, the imeta tag is correct, and the desktop shows a broken-image placeholder that opens an empty image viewer. That is a worse failure to debug than the current refusal, because it looks like a permissions or storage problem rather than a formatting one.

To reproduce on main today, lift the allowlist first:

--- a/crates/buzz-cli/src/client.rs
+++ b/crates/buzz-cli/src/client.rs
-    if !ALLOWED_MIMES.contains(&mime.as_str()) {
-        return Err(CliError::Usage(format!("unsupported file type: {mime}")));
-    }
+    // temporarily mirror the relay's denylist instead of the CLI allowlist

then:

printf 'hello\n' > note.txt
buzz messages send --channel <uuid> --file note.txt --content "test"

The event body ends with ![image](https://<relay>/media/<sha>.bin).

If it's easier to land the two together, the fix here is three lines — embed image/* and video/*, emit [<original filename>](url) for anything else — and it also restores the filename, which the sha-named URL otherwise destroys.

Happy to open a PR against whichever #2963 fix you prefer as the base.

ams1 avatar Sep 05 '26 16:09 ams1

Adding data from main @ e9269cb (relay) with Desktop 0.5.27 and the current iOS build: a message sent with --file for an .stl (application/octet-stream) and a .zip renders as "Image unavailable" tiles on both desktop and iOS. On desktop the file card only appears when the message text contains a markdown link whose href equals the imeta url (resolveFileCard in markdownFileCard.ts looks the entry up through imetaByUrl); the CLI never writes such a link, so CLI attachments cannot produce a card. iOS shows the broken-image tiles even with the link present. Two small fixes would cover it: the CLI could append [filename](url) to the content for non-media attachments (or add filename to the imeta tag and have the renderers use it), and the gallery renderer could skip imeta entries whose m is not image or video.

nachumi-a2zoperations avatar Oct 09 '26 12:10 nachumi-a2zoperations

This looks fixed on main by #9168 (merged 2026-11-06). attachment_markdown in crates/buzz-cli/src/commands/messages.rs now embeds only JPEG, PNG, GIF, WebP and MP4 with ![…]. Any other attachment, such as a PDF or a Markdown file, is sent as a plain [name](<url>) link. If nobody sees it on a current build, this can probably be closed.

shani-singh1 avatar Nov 20 '26 01:11 shani-singh1