server: explicit opt-in tools via non-loopback addr, check cors host port (#32113)
* server: explicit opt-in tools via non-loopback addr, check host port * fix ci
This commit is contained in:
1 parent
e182fdad4a
commit
a1a68eb797
9 files changed
+91
-77
No files matched your search
@@ -13,6 +13,7 @@
|
||||
#include "llama.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <clocale>
|
||||
#include <exception>
|
||||
@@ -258,6 +259,17 @@ static bool server_setup_features(
|
||||
SRV_WRN("%s", "security: no API key is set and CORS allows all origins (see https://github.com/ggml-org/llama.cpp/pull/25655)\n");
|
||||
}
|
||||
|
||||
// tools can run shell commands: do not expose them to the network without auth
|
||||
const bool tools_enabled = !params.server_tools.empty() || !params.mcp_servers_config.empty() || !params.mcp_servers_json.empty() || params.ui_mcp_proxy;
|
||||
const bool loopback_only = std::all_of(params.hostnames.begin(), params.hostnames.end(), [](const std::string & h) {
|
||||
return string_ends_with(h, ".sock") || h == "localhost" || h == "::1" || h == "[::1]" || string_starts_with(h, "127.");
|
||||
});
|
||||
if (tools_enabled && !loopback_only && params.api_keys.empty() && !params.server_tools_allow_unauth) {
|
||||
SRV_ERR("%s", "security: server tools, MCP servers or MCP proxy are enabled on a non-loopback address without an API key\n");
|
||||
SRV_ERR("%s", "set --api-key, bind to 127.0.0.1, or pass --allow-unauthenticated-tools on a trusted network\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> warn_names;
|
||||
if (role_type == SERVER_ROLE_ROUTER) {
|
||||
warn_names.push_back("router mode");
|
||||
|
||||
Reference in new issue
Block a user