mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
fix(security): grant private AI endpoints by exact origin, dialled pinned
ALLOW_LOCAL_AI_PRIVATE_HOSTS=true let any user of the instance point the Local provider or the OpenAI-compatible gateway at any private address the server could reach, the metadata range included, and a granted host was dialled with no connect-time pin at all. AI_PRIVATE_ORIGINS grants a private AI endpoint with the exact-origin grammar NOTIFICATION_PRIVATE_ORIGINS and NIGHTSCOUT_PRIVATE_ORIGINS use. A granted call goes through the pinned operator-approved dispatcher: redirects forbidden, and metadata, link-local and unspecified answers dropped at dial time even for a granted name. Everything else stays on the public pin. The Local client (buffered and streaming) and the gateway and admin-key tags of the OpenAI client all take their policy from one function. The host-list form of ALLOW_LOCAL_AI_PRIVATE_HOSTS keeps working with the same pinning; a never-grantable literal or a host:port entry is refused with a one-time warning. Its "true" form grants nothing any more and is reported in the boot readiness summary with the replacement. A failed lab-report scan no longer puts the endpoint's response body into the wide event; status and model stay. The response to the caller never carried it.
This commit is contained in:
1 parent
f7b3ce6ee0
commit
1a674cf4b0
20 files changed
+508
-181
No files matched your search
@@ -9,14 +9,13 @@
|
||||
* instead of shipping silently.
|
||||
*
|
||||
* The LOCAL AI client and (since v1.37.30) the openai-client's gateway and
|
||||
* admin-key tags are the deliberate exceptions: they stay CONDITIONAL
|
||||
* (`requirePublicHost: !allowPrivate`) so an operator can opt into LAN hosts
|
||||
* via `ALLOW_LOCAL_AI_PRIVATE_HOSTS`. v1.18.7 (SECURITY LOW) — that flag is
|
||||
* now a host ALLOWLIST (`true` = any private host; a comma-separated list =
|
||||
* only those), resolved by `isLocalAiHostAllowed`. We assert the client keeps
|
||||
* the conditional shape AND derives `allowPrivate` from the allowlist helper
|
||||
* (not a raw `=== "true"` binary), never an unconditional `true` (which would
|
||||
* break LAN local models) and never absent (which would re-open the default).
|
||||
* admin-key tags are the deliberate exceptions: an operator can grant a LAN
|
||||
* endpoint. Since v1.39.3 the grant is an exact origin (`AI_PRIVATE_ORIGINS`,
|
||||
* or the legacy host list) and the call is dialled through the pinned
|
||||
* operator-approved dispatcher, never unpinned; the whole policy comes from
|
||||
* `aiEgressPolicyFor`. We assert every AI dial site spreads that policy, and
|
||||
* that neither an unconditional `false` (no pin) nor a local
|
||||
* `isLocalAiHostAllowed` decision (a grant with no pin) reappears there.
|
||||
*/
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
@@ -35,8 +34,9 @@ describe("SSRF requirePublicHost pin inventory", () => {
|
||||
it("openai-client routes person-typed base URLs through the allowlist with a pinned floor", () => {
|
||||
const src = read("ai/openai-client.ts");
|
||||
expect(src).toMatch(
|
||||
/requirePublicHost:\s*this\.isGateway \|\| this\.type === "admin-key"\s*\? requirePublicHostFor\(this\.config\.baseUrl\)\s*:\s*true/,
|
||||
/this\.isGateway \|\| this\.type === "admin-key"\s*\?\s*aiEgressPolicyFor\(url\)\s*:\s*\{\s*requirePublicHost:\s*true as const\s*\}/,
|
||||
);
|
||||
expect(src).not.toMatch(/requirePublicHost:\s*false/);
|
||||
});
|
||||
|
||||
it("anthropic-client pins the BYO base-URL outbound unconditionally", () => {
|
||||
@@ -83,16 +83,18 @@ describe("SSRF requirePublicHost pin inventory", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("local AI client keeps the pin CONDITIONAL (LAN escape hatch)", () => {
|
||||
it("local AI client dials every call through the shared egress policy", () => {
|
||||
const src = read("ai/local-client.ts");
|
||||
// Must carry the conditional form …
|
||||
expect(src).toMatch(/requirePublicHost:\s*!?\s*allowPrivate/);
|
||||
// … and must NOT be hardened to an unconditional true (that would break
|
||||
// a deliberately-private LAN local model).
|
||||
expect(src).not.toMatch(/requirePublicHost:\s*true/);
|
||||
// … and `allowPrivate` must come from the host-allowlist helper, not a
|
||||
// raw binary `=== "true"` (v1.18.7 — the flag became an allowlist).
|
||||
expect(src).toMatch(/allowPrivate\s*=\s*isLocalAiHostAllowed\(/);
|
||||
expect(src).not.toMatch(/ALLOW_LOCAL_AI_PRIVATE_HOSTS\s*===\s*"true"/);
|
||||
// Both the buffered and the streaming call derive the policy …
|
||||
expect([
|
||||
...src.matchAll(/const egress = aiEgressPolicyFor\(url\)/g),
|
||||
]).toHaveLength(2);
|
||||
// … and spread it into safeFetch …
|
||||
expect([...src.matchAll(/\.\.\.egress,/g)]).toHaveLength(2);
|
||||
// … with no local decision beside it: no hard-coded pin value (true
|
||||
// would break a granted LAN model, false would drop the pin) and no
|
||||
// grant check that could skip the operator-approved dispatcher.
|
||||
expect(src).not.toMatch(/requirePublicHost:\s*(?:true|false|!)/);
|
||||
expect(src).not.toMatch(/isLocalAiHostAllowed\(/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user