fix(opencode): allow blob URLs in the app CSP for image attachments - #140
Merged
Conversation
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.
Important
Problem
Image attachments inside the Amicode webview were unusable: a pasted screenshot staged a broken thumbnail, and sending with a staged image failed ("Failed to send prompt / failed to fetch"), stalling the chat until the image was removed. Text-only messages were unaffected.
Approach
Allow the blob scheme in the app server's shared Content-Security-Policy for the image, connection, and media source lists. The attachment pipeline stages thumbnails and sends payloads entirely through object URLs, and the policy omitted the one scheme those URLs use — so the display path and the send path failed for the same single reason.
Approaches Considered
Scope
Assumptions / Open Qs
What was failing
The shared policy listed network schemes and the data scheme but not the blob scheme:
img-src 'self' data: https:,media-src 'self' data:,connect-src * data:. The wildcard matches network schemes only; non-network schemes must be listed explicitly, which is whydata:was already there andblob:was not. Every attachment thumbnail is an object URL (image directive), and every send encodes the staged blob by fetching its object URL (connection directive) — both refused, hence the broken thumbnail and the failed send.What changed
Verification
global-clipboard): passing — the single-value paste behavior (one keystroke, one insert, with and without shift) is unchanged.Key Decisions
Constraints & Invariants
Source
Companion to harmoniqs/opencode#261 (image-pasting failure). Unrelated to PR #130 (copy/paste duplication fix) — different mechanism, fix, and verification; the addendum issue #141 records the distinction. Related seam work: harmoniqs/amicode#243. Design of record:
notes/image-attachment-csp.mdin the harness.Notes
The defect's diagnosis was pinned by source-independence: identical symptoms for screenshots, copied files, and picker attachments meant the fault sat in the shared pipeline or its policy — downstream of every paste path. Earlier tool versions fail the same way, consistent with a policy that predates the paste work.