Repository navigation
server: add --cors-* options - #25655
Conversation
|
Memo to myself: I'm going to test/merge this one |
|
@ngxson Definitely should have a separate documentation section in the server notes, at least with what you just wrote in the PR description. |
I think I can commit to the branch if you approve this proposal, @pwilkin? doc proposal : CORSBy default the server reflects any Enabling Recommended
Related flags: |
There was a problem hiding this comment.
LGTM
What's I tested :
-
default (*, credentials) behavior unchanged, startup warning fires
-
--agent / --tools switches default to localhost, explicit override works
-
reflects localhost / 127.0.0.1 / [::1], rejects everything else
-
/cors-proxy forwards only explicit proxy headers
-
test_security.py: 17/17 passed
-
adversarial: null origin, subdomain suffix, decimal/mapped IP, case, trailing dot all rejected
-
minor: "http://evil.com@localhost" accepted, host correctly parses as localhost per URL syntax, not exploitable: browsers never put userinfo in the Origin header (RFC 6454), no real request can carry this value
* server: add --cors-* options * add special "localhost" value * add tests * fix test * add link to PR
* server: add --cors-* options * add special "localhost" value * add tests * fix test * add link to PR
Overview
Traditionally, llama-server always enable CORS
*with no way to disable it. This was fine because llama-server endpoints were stateless, read-only and default config doesn't expose any sensitive data. The only risk was DoS which is not considered a vulnerability per llama.cpp's policy.However, with the addition of
--agentmode (built-in tools), server can now expose API that allow read/write arbitrary files. If combine with the relaxed CORS, it may allow malicious pages to access local file from server API.This PR introduce 4 flags, inspired by vllm:
--cors-origins--cors-methods--cors-headers--(no-)cors-credentialsBy default:
--cors-origins)Recommendations
Depending on use case
--cors-originsis optional--cors-originsto origin server address--cors-origins localhost(auto set via--agent)Requirements