Every model my llama-swap config starts on this machine receives the same flag: --cors-origins localhost. I set it as the boundary for a local inference endpoint and stopped thinking about it. Two commits to llama.cpp in November pushed me to read what that flag decides, and its reach is narrower than the way I had it filed 12.
The header decides who reads, not whether the request runs
The CORS middleware is what sets Access-Control-Allow-Origin. With localhost in force it reflects the Origin header only when that origin’s host is localhost, 127.0.0.1 or ::1, and it logs and skips the header for anything else 3. Before the November change, that special case was the whole of the flag’s effect on a request.
That effect covers reading a reply. A page whose own DNS name points at my listener is a different case, because once the name resolves the browser treats the request as same-origin and never asks the CORS question. No header is needed for that page to read what came back.
The Host check, and what it covers
Commit 2cbe0ec on 11 November, pull request 32098, added request_host_is_allowed and called it from request_origin_is_allowed, which is the function that can reject a request rather than decorate a response 12.
The first thing it tests is where the connection landed. If the connection did not arrive on a loopback address, the function returns true and the rest never runs. On a loopback arrival it reads the Host header and accepts only localhost, 0.0.0.0, ::, ::1, or a name in 127.0.0.0/8. A Host that matches the host part of one of the --cors-origins entries also passes. With the policy set to localhost there is no entry list to match, so any other Host returns false and the server answers 403 2.
Only after that does the function compare the Origin header’s host and port against Host, and treat equality as same-origin 2. A rebinding page satisfies that comparison by construction, which is why the Host check had to come first.
The wildcard skips the whole function
request_origin_is_allowed returns true on its first line when the policy is *, and * is the default value of --cors-origins 24. A stock server never reaches the Host check or the Origin comparison. The server prints a warning at startup when the policy is the wildcard and no API key is set, and that line is easy to read past when the listener sits on loopback 5.
The wildcard case is not theoretical. G3tSyst3m wrote it up in August: a page on another origin can send prompts to a local llama.cpp server and read the replies, and with --tools all set, malicious same-origin content such as a bookmarklet or an injected extension script can drive the model to execute local tools 6.
A listener on a real interface skips the check
The loopback test reads the connection’s local address, not the bind flag, so a server bound to a LAN address takes the early return and falls through to the Origin comparison. The comment on that comparison names the case it serves: the built-in UI opened through a LAN address. A rebinding page lands in the same branch, because its Origin and its Host carry the same name and port.
For a listener on a real interface the origin list still decides ordinary cross-origin requests, because the Origin and Host names differ there and the policy answers 403. What the origin list cannot decide is a rebinding page, where the two names agree by construction. That case is left to the API key and the tools refusal.
Each model command in my config carries --port ${PORT} --cors-origins localhost --model and no --host. llama-swap runs that command string as written and has no host setting of its own, so the bind comes from llama-server’s default of 127.0.0.1 7. That default keeps my setup on the loopback path. The LAN-bound case is worth knowing before opening a port, because the November Host check does not cover it.
Tools on a network address fail to start
The second change landed on 12 November, commit a1a68eb7, pull request 32113 5. When server tools, MCP servers or the MCP proxy are enabled, the server is not bound to loopback, and no API key is set, the process refuses to start. The error names the three ways out: set --api-key, bind to 127.0.0.1, or pass --allow-unauthenticated-tools on a trusted network 5.
The loopback test there is a string comparison against each --host value. A socket path, localhost, ::1, [::1], or an address starting with 127. counts as loopback. A hostname does not, even when it resolves to 127.0.0.1 5. That refusal does not consult the CORS policy at all, which makes it the one control in this group that holds whatever the origin list says.
What I check now
- The bind address. Loopback keeps the Host check in the request path and keeps the port off the network. A LAN address drops the Host check and leaves the key and the origin list deciding, and the origin list cannot tell a rebinding page from the interface it imitates.
- The build.
llama-server --versionreturns a build number, and 2cbe0ec is 11 November while a1a68eb7 is 12 November, so a binary from earlier in the fall carries neither 15. - The policy string.
*skips every check inrequest_origin_is_allowed, and*is the default, so the value has to be read rather than assumed 4. - The log after a rejected request. It carries the method, the path, the Host header, the Origin header and Sec-Fetch-Site, and the server answers 403 with a message pointing at
--cors-origins2. That line is how I confirm a policy is doing something. - Tools. I keep them off any listener that is not loopback, and I treat
--allow-unauthenticated-toolsas a decision that needs a written reason rather than a flag that quiets a startup error.
The setting I stopped trusting
I had one flag filed as the boundary for a local inference endpoint. It decides whether a page on another origin may read a reply, and on a listener bound to a real interface it also decides which ordinary cross-origin pages are refused. What it cannot do is separate a rebinding page from the interface that page imitates, because the two names agree. That separation comes from the bind address, the API key and the build. The November commits tightened two of those paths. The tools refusal tightened one of them without asking anything of the CORS policy, and the combination is what I check before I call an endpoint covered.
-
llama.cpp contributors. (2026, November 11). server: fix –cors-origins handling + protect against DNS rebinding (#32098) (Commit 2cbe0ec). GitHub. https://github.com/ggml-org/llama.cpp/commit/2cbe0ec429b849a88664e0f62388fc92a5abd699 ↩︎ ↩︎ ↩︎
-
llama.cpp contributors. (2026). tools/server/server-http.cpp at 2cbe0ec [Source code]. GitHub. https://github.com/ggml-org/llama.cpp/blob/2cbe0ec429b849a88664e0f62388fc92a5abd699/tools/server/server-http.cpp ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎
-
llama.cpp contributors. (2026). tools/server/server-http.cpp at 664f031 [Source code]. GitHub. https://github.com/ggml-org/llama.cpp/blob/664f031f492f7c14a147cfe6372e3915abacf731/tools/server/server-http.cpp ↩︎
-
llama.cpp contributors. (2026). LLaMA.cpp HTTP server [README]. GitHub. https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md ↩︎ ↩︎
-
llama.cpp contributors. (2026, November 12). server: explicit opt-in tools via non-loopback addr, check cors host port (#32113) (Commit a1a68eb7). GitHub. https://github.com/ggml-org/llama.cpp/commit/a1a68eb797fb1c336547696d7e11e33ec7b65cde and the same commit’s tools/server/server.cpp: https://github.com/ggml-org/llama.cpp/blob/a1a68eb797fb1c336547696d7e11e33ec7b65cde/tools/server/server.cpp ↩︎ ↩︎ ↩︎ ↩︎ ↩︎
-
G3tSyst3m. (2026, August 30). Llama.cpp, an Ice Cold CORS Light, and Command Execution: Put it on My Tab! G3tSyst3m’s Infosec Blog. https://g3tsyst3m.com/cors/Llama.cpp,-an-Ice-Cold-CORS-Light,-and-Command-Execution-Put-it-on-my-Tab!/ ↩︎
-
llama.cpp contributors. (2026). LLAMA.cpp HTTP server [README at a1a68eb7,
--hostdefault 127.0.0.1]. GitHub. https://github.com/ggml-org/llama.cpp/blob/a1a68eb797fb1c336547696d7e11e33ec7b65cde/tools/server/README.md ↩︎