Repository navigation
Studio: fetch a remote image URL instead of forwarding it to llama-server - #11160
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2261ea1f18
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if _messages_have_remote_image(payload.messages): | ||
| try: | ||
| await asyncio.to_thread(_inline_request_remote_images, payload) |
There was a problem hiding this comment.
Fetch remote images before switching the loaded model
When automatic model switching is enabled and this passthrough request names a different GGUF, the fetch occurs only after _maybe_auto_switch_model has loaded the target. A private, unreachable, or slow image URL can therefore evict the working model and then fail with 400 without ever generating; repeated invalid requests can continually churn model loads. Remote-image fetching should be part of the pre-switch image preflight, like the existing base64 validation, with the fetched result reused after switching.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This ordering matches main. On main a GGUF request with a remote image URL passed the pre-switch preflight, the switch loaded the target, and llama-server then fetched the URL, so an unreachable or slow host already evicted the resident model before failing. The pre-switch image preflight validates bytes the request already carries; it has never done network I/O. Moving the fetch there would put up to 60 seconds of fetching ahead of a model switch that can still reject the request for other reasons, and would need the fetched result threaded back through three different request shapes (chat, streaming Responses, Anthropic). Load churn is also not specific to images: any request naming a different model triggers a switch whether or not it later succeeds. The PR keeps the post-switch fetch and changes only who performs it.
There was a problem hiding this comment.
Checked against merge base f6cf06d: model switching already precedes remote-image dispatch and its possible network failure. This ordering is unchanged; moving network I/O into model preflight is separate from this SSRF fix.
|
@codex review |
|
Confirmed the GGUF path in studio/backend/routes/inference.py still forwards a remote image_url straight to llama-server, so the host does the fetch, and this branch pins and fetches it in Studio instead. Will get this reviewed. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a546d14c21
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Convert the encoded length back to the request budget's byte unit. | ||
| return f"data:{mime};base64,{b64}", (len(b64) * 3) // 4 |
There was a problem hiding this comment.
Enforce image budgets after PNG re-encoding
When a fetched JPEG or WebP is under the 10 MB download cap but expands substantially during decoding or PNG conversion, spent accounts only for the original compressed bytes. The subsequent _image_bytes_to_png_b64 call can therefore allocate and forward a PNG far beyond both the 10 MB per-image and 32 MB per-request limits—for example, a noisy 4096×4096 JPEG can fit under the fetch cap but become a roughly 48 MB PNG. A few such URLs can exhaust backend memory or produce an oversized llama-server request, so the final PNG size (and ideally decoded dimensions) must be checked against the remaining budget.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The limits here are download limits, and they are applied where Studio controls the bytes: 10 MB per fetched body, 32 MB and 8 URLs per request. PNG expansion afterwards is the existing contract for every image on this path. A base64 data URL on main goes through the same _image_bytes_to_png_b64 conversion, with no size or count limit at all, so the memory a request can cause through fetched URLs stays below what it can already cause by sending the bytes inline. Capping the re-encoded PNG against those budgets would refuse ordinary photos: a 4000x3000 photo-like JPEG of 4.0 MB re-encodes to a 23.9 MB PNG, which a 10 MB post-encode cap rejects, while main forwarded the same URL and llama-server decoded it. Pillow's MAX_IMAGE_PIXELS decompression-bomb guard still applies on decode.
There was a problem hiding this comment.
Reproduced the expansion with a deterministic 2048×2048 JPEG: 2,799,419 input bytes become 12,581,871 PNG bytes, with identical output hashes on base f6cf06d and head ed65282. The PR documents download budgets, and the existing inline-image decoder already permits this input. A post-encoding cap would change that existing image contract rather than repair a regression here.
There was a problem hiding this comment.
Confirmed independently against merge base f6cf06d: a 1.98 MB photographic JPEG re-encodes to 7.01 MB of PNG, so the expansion is real, but it is the pre-existing contract for every image on this path rather than something this PR introduces. A base64 data URL reaches the same converter on main with no size or count limit at all, so the fetched-URL path is the bounded case, not the new worst case. Capping post-encode would refuse ordinary photos that work today. Rejecting the suggested change and keeping the download budgets as they are.
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Verified source head
All 25 independent route safety assertions pass on both current revisions. The probe uses real FastAPI handlers, a model backend double, and a real local HTTP capture server for tool passthrough. Public image downloads use the real pinned fetcher; all four generation routes dispatch the same 30,343-byte PNG. Repeated the real socket drip test: a 0.2-second deadline takes 0.952 seconds on base and 0.200 seconds on current head. Ruff 0.6.9 and Earlier native Linux, macOS and Windows checks passed on Fresh scoped staging CI resolves the historical CI evidence gap:
The one backend failure is identical on both revisions: Head passed the exact browser scenario that timed out on base, plus the remaining model-settings, memory-estimate and IME checks. Screenshots were inspected. The staging run is red because it retains these observed baseline failures; no head-only failure was found. The old logs are unavailable, so their original failure causes remain unknown. Structured results, versions and screenshots are preserved. Mirror review converged at Approved after final-head verification, then squash-merged as |
|
@codex review |
6 similar comments
|
@codex review |
|
@codex review |
|
@codex review |
|
@codex review |
|
@codex review |
|
@codex review |
…ai#11160 _image_url_scheme only looked at the first 17 characters, so a URL whose colon sits past that window read as a bare base64 payload and was forwarded to llama-server untouched. Leading blanks do it: urlsplit drops them before reading a scheme, so "\n" * 13 + "http://169.254.169.254/" parsed as http everywhere except the guard. Skip those blanks, widen the scan past any real scheme, and only call a value a payload when it holds no colon and nothing outside the base64 alphabet.
The pinned fetcher sent no User-Agent, and image hosts refuse that: the same Wikimedia PNG answers 403 with no header and 200 with one. llama-server used to send its own, so moving the fetch into Studio made those URLs fail with the generic refusal. Reuse the _USER_AGENTS list _fetch_url_raw already picks from, chosen once per fetch, so the web fetch and the image fetch look the same to an origin.
|
Simulated this against the merge base #11160 | issue: REAL | PR as submitted: DEFECTIVE, 2 fixed by me | merge: YES
I ran a real llama-server (prebuilt CUDA bundle, SmolVLM-256M plus mmproj) and handed it a loopback Enumeration over the full input space13 scheme classes x 17 host forms x 5 padding classes, plus 5 payload shapes. Each cell is the branch the real code takes.
1195 cells, 18 identical, 1177 changed, 0 violations. The 18 identical cells are the data-URL shapes, so a user who never sends a remote URL is on a byte-identical path. The 4 payload cells are exactly the 4 base64 shapes, so no URL shape can pass as a payload. AST diff: 16 functions changed, 9 new, 0 bare excepts added. All 21 predicates of Two defects, both fixed here
Now the blanks are skipped, the window outruns any real scheme, and a value is only called a payload when it holds no colon and nothing outside the base64 alphabet. Still sub-microsecond: 0.198 us on a URL, 0.532 us on a 10 MB payload, so the scan stays bounded.
llama-server sent its own, so moving the fetch into Studio broke those URLs. Now reuses the Test powerThe suite run against the merge base: 39 failed, 1 passed. On the branch: 40 passed. Reverting the scheme gate fails exactly the 3 new padding cases; removing the User-Agent fails exactly the 1 new case. One vacuous pass worth naming: Blast radius
Cross-platform, each with a base arm
The one Windows head failure, Two behaviour changes worth naming rather than fixing
What I could not prove
|
|
@codex review |
|
@codex security review |
|
@codex review |
|
@codex review |
mahiatlinux
left a comment
There was a problem hiding this comment.
LGTM! Ready to merge, all manually checked.
…11160) Validate and fetch remote image URLs in Studio before GGUF dispatch, with pinned public addresses and bounded downloads.
Summary
Fixes #11010, an SSRF vulnerability in remote image handling for local GGUF models.
Previously, Studio passed a remote image URL directly to llama-server. llama-server then downloaded the image from the Studio machine without checking whether the address was public. An authenticated caller could use this to reach services on loopback, the local network, or a cloud metadata address.
What changed
Image generation requests
Studio now downloads remote images itself before sending a request to llama-server. The fetcher:
The downloaded image is converted to a PNG data URL. llama-server receives the image bytes and has no remote URL left to fetch.
This common path covers:
/v1/chat/completions, including tool passthrough/v1/messages/v1/responsesToken counting
/v1/messages/count_tokensalso sent image URLs to llama-server. Its/apply-templatehandler downloaded each image even though token counting only needs a fixed image marker.Studio now replaces remote images with a 1x1 placeholder before counting. This keeps the token count the same while preventing any network request.
/v1/chat/count_tokensalready refuses images and is unchanged.User-visible behavior
file:, FTP, or another URL schemeNon-GGUF remote-image behavior and remote-video behavior are unchanged. Token counting does not verify that a public HTTPS image exists because it intentionally performs no fetch.
Verification
Live checks compared
mainand this branch using the same vision GGUF and loopback canary servers:main, a loopback image URL returned 200 and the canary received a GET from llama-server. This branch returned 400 and made no connection.main, llama-server attempted to contact the cloud metadata address. This branch refused it before dispatch.The 20 new route-level test cases cover OpenAI, Anthropic, Responses, tool passthrough, token counting, private-address and scheme refusal, fetch failures, base64 compatibility, and both request limits. All directly affected tests pass, and Ruff is clean.
The broader selected backend suite completed with 11,002 passing tests and the same three failures and ten setup errors seen on
main, with no new failures.