[PR #553] [CLOSED] serve: image sources - network paths refused, URLs capped and fetched outside the FIFO, no local files for other origins' pages #2688

Closed
opened 2026-11-04 02:02:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/553
Author: @sergqwer
Created: 10/2/2026
Status: ❌ Closed

Base: main ← Head: pr/image-sources


📝 Commits (1)

  • 04a0cd2 serve: image sources - network paths refused, URLs capped at 32 MiB and fetched outside the FIFO, no local files for other sites' pages

📊 Changes

2 files changed (+210 additions, -12 deletions)

View changed files

📝 serve/server.py (+65 -12)
📝 serve/test_server.py (+145 -0)

📄 Description

Vision.load() takes any image source a request names:

  • a data: URL;
  • any http(s) URL, read whole with no size cap, under the global request FIFO;
  • file://...;
  • any path os.path.isfile accepts.

Three problems, all in serve/server.py:

  1. Network paths. A UNC path (\host\share\x.png, //host/share/..., \?\UNC\..., file://host/share/...) makes Windows open an SMB connection to that host and sign in with the user's NTLM credentials, at the first os.path.isfile. These are now refused before anything looks at the path. file://host/... was also read as a relative path before.
  2. URL size and the FIFO.
    • A URL is read up to 32 MiB (IMAGE_URL_MAX), and a larger Content-Length is refused unread.
    • A URL that cannot be read is a 400 that says so, not a dropped connection.
    • The download happens before the FIFO is taken: under it, a slow image server held every other request for up to 60 s.
  3. Pages of another origin. With no api_key (the default), /v1/messages and /v1/chat/completions read the body as JSON whatever its Content-Type. So any web page the user opens can send a text/plain POST, a simple request with no CORS preflight, and have the server read a local file as an image. The page gets no answer to read unless cors_origins allows it, but the file is read, and a UNC path leaks the hash.
    • A request whose Origin is not the server's own (nor in trusted_origins) may now send only data: and http(s) images. That is _foreign_origin(), factored out of _own_page().
    • Clients that send no Origin (CLI tools, SDKs, agents) and Strata's own page work as before.

Tests (ImageSources): each network form is refused without isfile being called; the cap, with and without Content-Length, and a 404; the download runs with the FIFO free; a foreign-origin request is refused on both APIs while the allowed forms pass. Serve tests: 176 OK (7 skipped).

🤖 Generated with Claude Code

https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/553 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/image-sources` --- ### 📝 Commits (1) - [`04a0cd2`](https://github.com/Niko1221/Strata/commit/04a0cd2a2df2a3827198bcac3e0ae3ae3cff0c24) serve: image sources - network paths refused, URLs capped at 32 MiB and fetched outside the FIFO, no local files for other sites' pages ### 📊 Changes **2 files changed** (+210 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+65 -12) 📝 `serve/test_server.py` (+145 -0) </details> ### 📄 Description `Vision.load()` takes any image source a request names: - a `data:` URL; - any `http(s)` URL, read whole with no size cap, under the global request FIFO; - `file://...`; - any path `os.path.isfile` accepts. Three problems, all in `serve/server.py`: 1. **Network paths.** A UNC path (`\host\share\x.png`, `//host/share/...`, `\?\UNC\...`, `file://host/share/...`) makes Windows open an SMB connection to that host and sign in with the user's NTLM credentials, at the first `os.path.isfile`. These are now refused before anything looks at the path. `file://host/...` was also read as a relative path before. 2. **URL size and the FIFO.** - A URL is read up to 32 MiB (`IMAGE_URL_MAX`), and a larger `Content-Length` is refused unread. - A URL that cannot be read is a 400 that says so, not a dropped connection. - The download happens before the FIFO is taken: under it, a slow image server held every other request for up to 60 s. 3. **Pages of another origin.** With no `api_key` (the default), `/v1/messages` and `/v1/chat/completions` read the body as JSON whatever its Content-Type. So any web page the user opens can send a `text/plain` POST, a simple request with no CORS preflight, and have the server read a local file as an image. The page gets no answer to read unless `cors_origins` allows it, but the file is read, and a UNC path leaks the hash. - A request whose `Origin` is not the server's own (nor in `trusted_origins`) may now send only `data:` and `http(s)` images. That is `_foreign_origin()`, factored out of `_own_page()`. - Clients that send no `Origin` (CLI tools, SDKs, agents) and Strata's own page work as before. Tests (`ImageSources`): each network form is refused without `isfile` being called; the cap, with and without `Content-Length`, and a 404; the download runs with the FIFO free; a foreign-origin request is refused on both APIs while the allowed forms pass. Serve tests: 176 OK (7 skipped). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:02:23 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2688
No description provided.