fix(recraft): re-host generated images to signed artifact URLs (F4)#112
Merged
Conversation
limner_generate_recraft returned Recraft's ephemeral (~24h) CDN url directly, while DALL·E, upscale, vectorize, and compose all re-host their output bytes to a signed Limner /artifact capability URL. The cause: the generate handler never requested inline bytes, so the transport returned (and preferred) Recraft's hosted url, which has no bytes to re-host. Request response_format=b64_json on the generation call (text-to-image and image-to-image), mirroring upscale/vectorize, so the bytes flow through the existing maybeDeliver -> uploadArtifact path and out as a signed URL. Two supporting fixes: - SVG-aware mime sniffing: a vector_illustration b64 result is now stamped image/svg+xml (via looksLikeSvg) instead of the raster default, so the delivered artifact's extension/content-type match the bytes. - Url-only fallback: if a style ignores response_format and Recraft still returns a hosted url, the transport fetches those bytes through the existing SSRF-guarded fetchInputImage, so no provider CDN url ever reaches the client. The responseFormat hint is internal (set by the MCP tool layer), not exposed on the user-facing tool schema. Tests: rewrote the recraft dispatch test (which had encoded the bug) to assert re-hosting + a b64_json request; added the url-only fallback case; added transport tests for response_format forwarding (JSON + multipart) and SVG sniffing. Suite 665 -> 670. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Jim Vinson <jim@vinson.org>
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.
F4 — Recraft re-host
limner_generate_recraftreturned Recraft's ephemeral (~24h) CDN url directly, while DALL·E,upscale,vectorize, andcomposeall re-host their output bytes to a signed Limner/artifactcapability URL (#63, #93). Root cause: the generate handler never requested inline bytes, so the transport returned (and preferred) Recraft's hostedurl, which has no bytes to re-host.Fix
Request
response_format=b64_jsonon the generation call (text-to-image and image-to-image), mirroringupscale/vectorize(pipelines.ts), so the bytes flow through the existingmaybeDeliver→uploadArtifactpath and out as a signed URL. TheresponseFormathint is internal (set by the MCP tool layer), not exposed on the user-facing tool schema.Two supporting fixes:
vector_illustrationb64 result is stampedimage/svg+xml(vialooksLikeSvg) instead of the raster default, so the delivered artifact's extension/content-type match the bytes.response_formatand Recraft still returns a hosted url, the transport fetches those bytes through the existing SSRF-guardedfetchInputImage, so no provider CDN url ever reaches the client.Tests
img.recraft.aiurl) to assert re-hosting + ab64_jsonrequest.response_formatforwarding (JSON + multipart) and SVG sniffing.Suite 665 → 670 passing. Typecheck + lint clean.
Verification
After deploy,
limner_generate_recraftreturns a signedmcp.limner.us/artifact/...URL (norecraft.aihost); tampered/expired sig → 403 like the other artifact paths.🤖 Generated with Claude Code