Archived
server: bound, gate and sanitize every request entry point
Prepared for exposing the dashboard and the API beyond the local machine. Each piece answers a finding from the review; none changes what a legitimate client sees. Parsing. Six entry points still called json::parse with no bound on the tree: the two WebSocket sessions, the image form's loras field, the two re-parses of template kwargs, the control-vector POST and the lora-admin body. A legal frame or body of brackets alone built a tree whose teardown recurses once per level -- one worker stack, one process. They all go through parse_json_bounded now, the body cap's own value and depth limits. The same reasoning already refused deep bodies on the generation routes; frames and form fields were the ones that never passed a gate. Errors. ApiError::dump threw on invalid UTF-8, and URL-decoded params reach messages without passing a JSON parser: a 404 becomes a 500, or worse a closed connection. The dumps replace bad bytes instead of dying. Logs. Session labels and echoed request text reach the log; an embedded newline forged a line and an escape sequence drove the terminal reading it. log_sanitize filters control bytes at the entry points -- labels, refusal logs, the exception handler -- while the three loggers that print multi-line reports deliberately keep their newlines. The browser. The dashboard page ships a CSP (its script talks only to its own origin) and X-Frame-Options DENY; every response carries X-Content-Type-Options: nosniff. And the loopback-only guards -- control-vector default, runtime LoRA, diagnostics -- now treat a cross-origin browser as the remote client it is: a hostile page reaches them through the victim's own browser, which is exactly loopback. Origin not matching Host refuses; same-origin and non-browser traffic are untouched. The gate. The API key's path exemptions are method-scoped (reads, plus the POST /ping of the health-check convention), so an exemption can never ride a method no route answers. An empty --api-key value is now a startup error rather than a server that looks guarded. SSE. In the vendored httplib 0.46 an exception escaping a content provider aborts the process; the provider ends the response instead. Upstream's 0.54 serve_guarded fixes the cause -- the vendor lift is owed either way, and the catch is harmless belt until it.
This commit is contained in:
1 parent
a28221eb6a
commit
b9c685a9c3
16 files changed
+245
-48
No files matched your search
+8
-3
@@ -2070,7 +2070,7 @@ by 0.002-0.003 nats.
|
||||
|---|---|---|
|
||||
| `--host ADDR` | 0.0.0.0 | listen address |
|
||||
| `--port N` | 8000 | listen port |
|
||||
| `--api-key KEY` | none | require `Authorization: Bearer KEY` or `X-Api-Key: KEY` on every request but `/health`, `/v1/health`, `/ping` and the dashboard page (§6.6) |
|
||||
| `--api-key KEY` | none | require `Authorization: Bearer KEY` or `X-Api-Key: KEY` on every request but `/health`, `/v1/health`, `/ping` and the dashboard page (§6.6); the key must be non-empty |
|
||||
| `--served-model-name NAME` | container's name | the model id `/v1/models` lists, the metrics carry and a response names when its request named none. A request may name any model; the loaded one serves it |
|
||||
| `--mm-max-patches N` | auto | patches one vision-encoder pass carries, and so the largest image (a patch is 16x16 pixels, 14x14 on GLM-5.3). `auto` is 16384 when the container carries a vision tower; 0 serves text only and keeps the tower off the card. A pass is not one tower invocation: inside it the tower batches at most 8 tiles per weight read, and the pass size may reduce that (4 tiles at the 64-pixel grid with the default 16384 patches); a picture contributes a separate pass per grid. See the concurrency notes for Unlimited-OCR (§5.17) |
|
||||
| `--override-chat-template PATH` | container's | a Jinja chat template file served in place of the container's. The reply format (reasoning markers, tool calls) is derived from it too, unless the architecture plugin declares one. An unreadable or empty file stops startup |
|
||||
@@ -3594,11 +3594,16 @@ With a key, every request must carry `Authorization: Bearer KEY` (or Anthropic's
|
||||
or it is answered 401, `/tokenize` and `/server_info` included. Exempt are `/health`, `/v1/health` and
|
||||
`/ping`, because load balancers cannot send a bearer token, and the dashboard page (`/`,
|
||||
`/dashboard`), which holds no data: on a 401 it asks for the key, keeps it in the browser's storage
|
||||
and sends it on every data fetch.
|
||||
and sends it on every data fetch. The exemption follows those paths' methods -- reads, plus the
|
||||
`POST /ping` of the health-check convention -- so it cannot follow a method no route answers.
|
||||
An empty `--api-key` value is a startup error: it would guard nothing.
|
||||
|
||||
Without a key, `/diagnostics` answers only loopback clients (others get 403), because it describes
|
||||
the host: kernel, boot parameters, PCI layout, memory limits. Read it on the machine, or start the
|
||||
server with `--api-key`.
|
||||
server with `--api-key`. The same loopback-only rule covers the control-vector default and runtime
|
||||
LoRA loads, and a browser page on another origin does not qualify as a loopback client even when
|
||||
its own machine serves the port: that is how a hostile web page would reach these routes through a
|
||||
victim's browser, and a request that says `Origin: http://evil` is refused the way a remote one is.
|
||||
|
||||
The key is not encrypted in transit. On a network you do not control, bind to localhost behind a
|
||||
TLS-terminating reverse proxy:
|
||||
|
||||
Reference in new issue
Block a user