Repository navigation
Reject HEIC/HEIF attachment uploads with a reason - #2170
Merged
Merged
Conversation
Chromium (web app and Electron shell) has no HEVC decoder and no provider image input accepts HEIC, but the server stored and served pasted iPhone photos verbatim as a localImage. The composer and timeline showed a broken thumbnail and the model silently received nothing. bb ships no HEIF transcoder, so the server now refuses HEIC/HEIF uploads (by MIME type or extension) with an actionable 400, and the composer shows the server's reason instead of a bare "Failed to attach". Co-Authored-By: Claude <[email protected]>
Extension-only HEIC uploads with a non-image MIME type were stored as a plain localFile on main, which is not the broken case; keep that path so a user can still hand the raw file to an agent. Refuse only the image/heic and image/heif classifications that produced a broken thumbnail and an image the model never received. Co-Authored-By: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
POST /api/v1/projects/:id/attachmentsstored and served a pasted or dropped.heicfile verbatim and classified it as alocalImagebecause its MIME type starts withimage/. Nothing downstream can decode HEIC/HEIF: Chromium (the web app and the Electron shell) ships no HEVC decoder, so the composer thumbnail and the timeline<img>showed the broken-image glyph, and no provider image input accepts HEIC either (Codex replaced it with "image content omitted because it could not be processed"). The user saw a broken picture and the model silently received nothing. Issue: #1670. Report: https://get-bb.github.io/reports/issues/1670.htmlThis PR is a stopgap, not the rendering fix the issue asks for. Rendering HEIC requires an HEVC decoder that bb does not have. The only portable option is libheif/libde265 compiled to WASM (
libheif-js, LGPL-3.0, ~1.4 MB, a patent-encumbered codec that Chromium itself declines to ship), run either in the browser before upload or in the server process (where a 12 MP photo blocks the event loop for about two seconds unless it moves to a worker; measured 0.1 s decode + 0.1 s encode for a 1.4 MP sample). That dependency and placement decision belongs to the maintainers, so this PR does the safe part: it turns the silent failure into an immediate, explained refusal. The issue stays open for the transcoding work (Refs, notFixes).What changed
apps/server/src/services/projects/attachments.ts:storeAttachmentrefuses uploads whose MIME type isimage/heic,image/heif, or their-sequencevariants with400 invalid_requestand the messageHEIC images are not supported. Convert the image to JPEG or PNG before attaching it.This is exactly the set of uploads that used to become a brokenlocalImage: Chromium labels a pasted or dropped.heicimage/heic, andbb project attachment uploadinfers the same from the extension. The same bytes sent with a non-image MIME type (for example--mime-type application/octet-stream) still store as a plainlocalFile, as on main, so a user can hand the raw file to an agent that converts it on the host. Every client (web, desktop, mobile document picker, CLI, SDK) gets the same answer. No wire change between server and daemon.apps/app/src/components/thread/embedded-chat/useComposerAttachmentUploads.ts: the follow-up and queued-message composers now show the server's reason (Failed to attach IMG_0001.heic: HEIC images are not supported. ...) instead of a bareFailed to attach: IMG_0001.heic. The new-thread composer already did this throughgetMutationErrorMessage; this brings the other composers in line. Transport errors keep the old generic text.packages/templates/src/templates/bb-guide-projects.md) and the bb-cli skill (apps/server/src/services/skills/builtin-skills/bb-cli/SKILL.md) mention thatimage/heicandimage/heifuploads are rejected.Revision after review: the first version also rejected by
.heic/.heifextension alone, which blocked the explicit non-image upload path that main handled correctly as alocalFile. The rejection is now MIME-only and the test pins thelocalFilepath.Not included: an
onErrorfallback tile inAttachmentPreview/ConversationAttachmentsfor threads that already hold HEIClocalImageattachments. That is a general broken-image UI concern, independent of HEIC, and is left for a follow-up.Deviation from the report's proposed fix: it proposed transcoding HEIC to JPEG at upload with a WASM decoder. Not done here for the reasons above. If the maintainers want HEIC to just work, the smallest follow-up is a browser-side conversion before upload (decode with
libheif-js, encode withOffscreenCanvas.convertToBlob("image/jpeg")), mirroring the mobile app, which already asks the iOS picker for JPEG instead of HEIC. The server check then stays as the backstop for programmatic uploads.How you verified
New tests, both fail on
origin/mainand pass here:apps/server/test/public/public-project-attachments.test.ts>rejects HEIC/HEIF image uploads instead of storing an image nothing can render. Withattachments.tsreverted toorigin/main:AssertionError: expected 201 to be 400(the HEIC was stored as alocalImage). It also asserts thatimage/heif; charset=binaryis rejected and that the same bytes asapplication/octet-streamreturn201 {"type":"localFile"}.apps/app/src/components/thread/embedded-chat/useComposerAttachmentUploads.test.tsx>shows the server's reason when it refuses an upload. On main:Expected: "Failed to attach IMG_0001.heic, shot.png: HEIC images are not supported. ...",Received: "Failed to attach: IMG_0001.heic, shot.png".Run from the committed tree at
d28f3fc34(git status --porcelainempty,origin/mainatf6fb434ab):pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/app --filter=@bb/templates --filter=@bb/cli:Tasks: 7 successful, 7 total.pnpm exec turbo run test --filter=@bb/server --filter=@bb/templates --filter=@bb/cli: cli 48/48 files; templates 6/6 files; server 193/195 files. The two server failures are unrelated to this change:internal-skill-trees.test.tsasserts file mode 0644 and gets 0664 on this workstation's umask 0002 (fails identically on clean main, passes in CI), andplugin-update.test.ts > waits one full interval when no plugins are eligible for update checkshit its 5 s timeout under a load average of 35; it passes alone with--testTimeout=60000(test body 1.9 s).pnpm exec turbo run test --filter=@bb/app:409 passed (409)files,3157 passed | 3 skipped; vitest also reported one unhandled post-teardown timer fromThreadTimelineRows.windowing.test.tsx(document is not definedinuseScrollToSearchedMessage.ts), a file this PR does not touch; that file and the composer test pass cleanly when re-run together.Manual, on a dev instance of this branch, re-running the report's repro:
curl -F "[email protected];type=image/heic" .../attachments(nokiaautumn_1440x960.heic) returns400 {"code":"invalid_request","message":"HEIC images are not supported. Convert the image to JPEG or PNG before attaching it."};type=image/heifwith anIMG.HEIFfilename is also rejected;type=application/octet-streamreturns201 {"type":"localFile",...}; a PNG returns201 {"type":"localImage",...}.bb project attachment upload <project> --client-file sample.heic(MIME inferred from the extension) printsError: HTTP 400: HEIC images are not supported. ...; with--mime-type application/octet-streamit printsAttachment uploaded: sample-...heic.Fileinto the new-thread composer and into a thread's follow-up composer (first revision; the app code and theimage/heicserver response are unchanged since): no<img>is created, and the composer shows the reason inline.Refs #1670
Independent verification
Verified round 2 on
d28f3fc34(merge-base withorigin/mainf6fb434ab;origin/mainhas since gained only the unrelatedc942421a4), in a separate worktree with its own dev instance.Commands and results:
git checkout origin/main -- apps/app/src/components/thread/embedded-chat/useComposerAttachmentUploads.ts apps/server/src/services/projects/attachments.ts, thenpnpm exec vitest run test/public/public-project-attachments.test.ts(apps/server):AssertionError: expected 201 to be 400inrejects HEIC/HEIF image uploads instead of storing an image nothing can render(1 failed | 3 passed).pnpm exec vitest run src/components/thread/embedded-chat/useComposerAttachmentUploads.test.tsx(apps/app):Expected: "Failed to attach IMG_0001.heic, shot.png: HEIC images are not supported. ...",Received: "Failed to attach: IMG_0001.heic, shot.png"(1 failed | 3 passed).git checkout HEAD -- <same files>: both files 4/4 pass.pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/app --filter=@bb/templates --filter=@bb/cli:Tasks: 7 successful, 7 total.pnpm exec turbo run test --filter=@bb/server --filter=@bb/templates --filter=@bb/cli --filter=@bb/app --force: app 409/409 files, cli 48/48, templates 6/6, server 194/195 files (1823/1824 tests). The one failure isinternal-skill-trees.test.ts(0644 vs 0664 file mode under umask 0002), a known local-only failure unrelated to this PR.autumn_1440x960.heic):curl -F "[email protected];type=image/heic"->400 {"code":"invalid_request","message":"HEIC images are not supported. ..."};type=image/heif-> 400;type="Image/HEIC; charset=binary"-> 400;type=application/octet-stream->201 {"type":"localFile",...}; no explicit type (curl default octet-stream) -> 201 localFile; PNG ->201 {"type":"localImage",...}.bb project attachment upload <proj> --client-file sample.heic->Error: HTTP 400: HEIC images are not supported...; with--mime-type application/octet-stream->Attachment uploaded: sample-...heic.image/heicFileinto the new-thread composer and into a thread's follow-up composer: no<img>pointing at/attachments/contentis created; the new-thread composer showsHEIC images are not supported. Convert the image to JPEG or PNG before attaching it.inline and the follow-up composer showsFailed to attach IMG_0001.heic: HEIC images are not supported. .... The original broken-thumbnail symptom no longer reproduces.storeAttachmenthas a single caller (the upload route), that the mobile document picker surfaces the 400 through itsBbHttpErrortoast, and that the mobile photo picker already requests JPEG for HEIC assets, so the new server policy matches the existing mobile stance.Residual risks (acknowledged by the PR): HEIC still cannot be attached as an image until a transcoder lands (issue stays open via
Refs); existing threads with stored HEIClocalImageattachments still render the broken-image glyph; HEIC bytes uploaded with a misleading non-HEIC image MIME type are not sniffed. Minor doc gap: the bb-plugin-authoring skill's SDK attachment paragraph mentions the size caps but not the HEIC rejection.