Files
rays cc31b1433d fix(security): restrict LLM requests to operator-approved destinations
The analyze, chat, verify-key and model-list routes sent server-side
requests to a caller-supplied base URL guarded only by a pre-flight
denylist. Callers could choose arbitrary hosts and paths, reach shared
address space and metadata ranges, drive local LLM write APIs, and use
DNS rebinding to deliver server-held keys to loopback services.

Requests now select an entry of an immutable destination registry built
at startup from the built-in provider catalog, local Ollama/LM Studio,
and operator environment variables (DOCTOR_LLM_ALLOWED_BASE_URLS and the
existing base URL variables). Outbound URLs are built from the approved
entry, resolved addresses are checked at connect time inside the shared
connector, redirects are never followed or treated as success, and error
responses no longer reflect upstream bodies or network details. The UI
shows localized operator guidance, a static rule enforces disabled
redirects and policy-managed sessions, and .comfyignore keeps tests and
tooling out of the published archive.
2026-10-13 12:22:39 +08:00

27 lines
982 B
JavaScript

/**
* User-facing text for LLM route error codes.
*
* The backend returns stable error codes (for example `destination_not_allowed` when the requested
* base URL is not an operator-approved destination). Known codes are shown as localized guidance;
* any other value is shown unchanged.
*/
import { t } from "./i18n_fallback.js";
export const DESTINATION_NOT_ALLOWED = "destination_not_allowed";
const DESTINATION_NOT_ALLOWED_FALLBACK =
"This LLM endpoint is not approved on this server. Ask the server operator to add it to DOCTOR_LLM_ALLOWED_BASE_URLS.";
/**
* @param {string} codeOrMessage - Error code or message from an LLM route.
* @param {Object} uiText - Loaded UI text dictionary (may be empty).
* @returns {string}
*/
export function describeLlmError(codeOrMessage, uiText) {
if (codeOrMessage === DESTINATION_NOT_ALLOWED) {
return t(uiText, "llm_destination_not_allowed", DESTINATION_NOT_ALLOWED_FALLBACK);
}
return codeOrMessage;
}