From fb829540771e6f55c33ba2336917a84337bf518b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 27 Aug 2026 08:48:00 +0200 Subject: [PATCH 1/3] Let the operator provider reach an allowlisted private host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The global admin provider's base URL is operator-typed in the admin settings, but the client pinned requirePublicHost unconditionally for its tag — so an operator pointing it at a private OpenAI-compatible proxy (an OAuth sidecar on the instance's own Docker network) got a safeFetch refusal on every call, indistinguishable from an outage. The admin-key tag now consults the same ALLOW_LOCAL_AI_PRIVATE_HOSTS policy as the user-configured gateway: a public URL never consults the allowlist, a private host without an entry is refused exactly as before, and both ends of the grant are the operator's own. The codex tag stays hard-pinned; its base URL is a repository constant. Every non-operator admin-key construction pins the public api.openai.com constant, so the personal-key posture is unchanged. The test asserting the old blanket pin is split into the three cases that actually differ: allowlisted private host passes, unlisted private host still refuses, codex refuses even a blanket allowlist. --- .../openai-compatible-client.test.ts | 52 ++++++++++++++++--- src/lib/ai/openai-client.ts | 35 +++++++++---- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/src/lib/ai/__tests__/openai-compatible-client.test.ts b/src/lib/ai/__tests__/openai-compatible-client.test.ts index dfac04cbb..653ff5181 100644 --- a/src/lib/ai/__tests__/openai-compatible-client.test.ts +++ b/src/lib/ai/__tests__/openai-compatible-client.test.ts @@ -9,9 +9,11 @@ import { singleUserTurn } from "../types"; * Two properties carry the security weight of this provider and are pinned * here rather than left to review: * - * 1. The pinned `admin-key` / `codex` tags keep `requirePublicHost: true` - * no matter what the operator allowlisted. Only the gateway tag — whose - * base URL a person typed — consults the allowlist. + * 1. The `codex` tag keeps `requirePublicHost: true` no matter what the + * operator allowlisted — its base URL is a repository constant. The + * gateway and `admin-key` tags — the two whose base URL a person can + * type — consult the allowlist, and without an allowlist entry a + * private host is refused exactly as before (v1.37.30). * 2. The SSRF floor under the gateway is `isPublicUrl`, which is the same * floor the Local provider sits on, including every IPv4 / IPv6 * alt-notation class. @@ -168,12 +170,32 @@ describe("OpenAI-compatible gateway — host policy", () => { expect(fetchMock).toHaveBeenCalledTimes(1); }); - it("keeps the pinned tags on requirePublicHost even when the operator allowlisted the host", async () => { + // v1.37.30 — the admin-key tag joined the allowlist policy: its base URL + // is operator-typed in exactly one place (the global provider in the admin + // settings, e.g. pointed at a private OpenAI-compatible OAuth proxy), and + // the allowlist is the operator's own grant. The floor is unchanged: a + // private host WITHOUT an allowlist entry is refused, and the codex tag + // stays hard-pinned because its base URL is a repository constant. Note + // that every non-operator admin-key construction in the app pins the + // public `api.openai.com` constant, so the personal-key posture cannot + // reach this branch. + it("admin-key consults the allowlist for an operator-typed private host", async () => { + const fetchMock = okReply(); + vi.stubGlobal("fetch", fetchMock); + vi.stubEnv("ALLOW_LOCAL_AI_PRIVATE_HOSTS", "openai-oauth-proxy"); + + await new OpenAIClient({ + apiKey: "unused-behind-proxy", + model: "gpt-4o", + baseUrl: "http://openai-oauth-proxy:10531/v1", + }).generateCompletion(jsonTurn()); + + expect(fetchMock).toHaveBeenCalledTimes(1); + }); + + it("admin-key still refuses a private host the operator did not allowlist", async () => { vi.stubGlobal("fetch", okReply()); - // The operator opened every private host for their local AI endpoint. - // That opt-in belongs to the gateway/local surface; a client carrying an - // OpenAI-issued key must not inherit it. - vi.stubEnv("ALLOW_LOCAL_AI_PRIVATE_HOSTS", "true"); + vi.stubEnv("ALLOW_LOCAL_AI_PRIVATE_HOSTS", ""); await expect( new OpenAIClient({ @@ -183,6 +205,20 @@ describe("OpenAI-compatible gateway — host policy", () => { }).generateCompletion(jsonTurn()), ).rejects.toMatchObject({ kind: "private_host" }); }); + + it("codex stays pinned to public hosts even under a blanket allowlist", async () => { + vi.stubGlobal("fetch", okReply()); + vi.stubEnv("ALLOW_LOCAL_AI_PRIVATE_HOSTS", "true"); + + await expect( + new OpenAIClient({ + apiKey: "codex-access-token", + model: "gpt-5.4", + baseUrl: "http://192.168.1.5:4000/v1", + providerType: "codex", + }).generateCompletion(jsonTurn()), + ).rejects.toMatchObject({ kind: "private_host" }); + }); }); describe("OpenAI-compatible gateway — JSON-mode dialect", () => { diff --git a/src/lib/ai/openai-client.ts b/src/lib/ai/openai-client.ts index 6cccde128..7e585896e 100644 --- a/src/lib/ai/openai-client.ts +++ b/src/lib/ai/openai-client.ts @@ -35,11 +35,13 @@ interface OpenAIClientConfig { * to log as "codex" instead. * * v1.33.1 (#470) — `openai-compatible` is the user-configured gateway - * (LiteLLM / OpenRouter / vLLM). It is the ONLY tag whose `baseUrl` is not - * a HealthLog-pinned constant, and the two behaviours below hang off it: - * the operator's private-host allowlist may apply, and the JSON-mode - * dialect is learned per endpoint instead of assumed. Every other tag - * keeps the pinned `api.openai.com` posture unchanged. + * (LiteLLM / OpenRouter / vLLM). Its `baseUrl` always comes from a person, + * and two behaviours hang off that: the operator's private-host allowlist + * may apply, and the JSON-mode dialect is learned per endpoint instead of + * assumed. `admin-key` carries a person-typed base URL in exactly one + * place (the operator's global provider in the admin settings) and shares + * the allowlist policy for it since v1.37.30; the dialect stays assumed. + * `codex` keeps the fully pinned posture. */ providerType?: OpenAIProviderType; } @@ -148,14 +150,25 @@ export class OpenAIClient implements AIProvider { // v1.21.5 — honour the caller's per-request timeout override; default 60 s. // v1.33.1 (#470) — the gateway tag reuses the Local provider's host // policy verbatim: public hosts always; a private host only when the - // operator allowlisted it via ALLOW_LOCAL_AI_PRIVATE_HOSTS. Every other - // tag stays pinned to `requirePublicHost: true` — `api.openai.com` is - // public and there is nothing to opt into. + // operator allowlisted it via ALLOW_LOCAL_AI_PRIVATE_HOSTS. + // + // v1.37.30 — the `admin-key` tag consults the same policy. Its base URL + // is the one other operator-typed URL in this client (an operator can + // point the global provider at a private OpenAI-compatible proxy, e.g. + // an OAuth sidecar), and both ends of the grant are the operator's own: + // the URL comes from the admin settings, the allowlist from the + // operator's environment. Every non-operator construction of this tag + // pins the public `api.openai.com` constant, for which the policy + // resolves to `true` without ever consulting the allowlist — so the + // personal-key posture is unchanged. The `codex` tag keeps the hard + // pin: its base URL is a repository constant, there is nothing an + // operator legitimately redirects. { timeoutMs: params.timeoutMs ?? 60_000, - requirePublicHost: this.isGateway - ? requirePublicHostFor(this.config.baseUrl) - : true, + requirePublicHost: + this.isGateway || this.type === "admin-key" + ? requirePublicHostFor(this.config.baseUrl) + : true, signal: params.signal, }, ); From 96d6f64ee6be2a45f6f7dc9063ccd07e810fae7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 27 Aug 2026 08:49:49 +0200 Subject: [PATCH 2/3] =?UTF-8?q?chore(release):=20v1.37.30=20=E2=80=94=20th?= =?UTF-8?q?e=20operator=20provider=20may=20cross=20into=20its=20own=20netw?= =?UTF-8?q?ork?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++++ docs/api/openapi.yaml | 2 +- package.json | 2 +- public/sw.js | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c3219229..8e2a6533d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.37.30] — 2026-08-27 + +An operator pointing the global AI provider at a private OpenAI-compatible proxy got a network refusal on every call, and nothing said why. + +### Fixed + +- The operator's global AI provider can now reach a private host, provided that host is named in ALLOW_LOCAL_AI_PRIVATE_HOSTS. Its base URL is typed by the operator in the admin settings, so it now consults the same allowlist as the user-configured gateway instead of being pinned to public hosts. A private host that is not allowlisted is refused exactly as before, personal API keys keep the pinned public posture, and the ChatGPT sign-in path stays fully pinned. + ## [1.37.29] — 2026-08-26 The chart range selector said points and meant days. Someone who weighs in twice a week picked "7 pts", saw two, and reasonably concluded the chart was broken. diff --git a/docs/api/openapi.yaml b/docs/api/openapi.yaml index c82740bb4..d8c8d92c4 100644 --- a/docs/api/openapi.yaml +++ b/docs/api/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.1.0 info: title: HealthLog API - version: 1.37.29 + version: 1.37.30 description: >- Self-hosted personal-health-tracking PWA — public API surface for the iOS native client and external ingest. diff --git a/package.json b/package.json index a525395bf..11b404c8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "healthlog", - "version": "1.37.29", + "version": "1.37.30", "description": "Self-hosted personal-health-tracking PWA with Withings integration, AI insights, and doctor-report PDF export.", "license": "PolyForm-Noncommercial-1.0.0", "homepage": "https://healthlog.dev", diff --git a/public/sw.js b/public/sw.js index 05a7ea72b..3162fe291 100644 --- a/public/sw.js +++ b/public/sw.js @@ -36,7 +36,7 @@ try { // v1.4.38.4 → v1.4.42. Do not hand-edit; bump `package.json` and rebuild. const CACHE_VERSION = (typeof self !== "undefined" && self.__APP_VERSION__) || - /* @sw-version-fallback */ "v1.37.29"; + /* @sw-version-fallback */ "v1.37.30"; const STATIC_CACHE = `healthlog-static-${CACHE_VERSION}`; const PAGE_CACHE = `healthlog-pages-${CACHE_VERSION}`; // v1.18.6 — read-only data cache for a curated allowlist of safe GET `/api/*` From 7aecae863d8d4755cc1034931f2be7efb5367822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 27 Aug 2026 08:56:53 +0200 Subject: [PATCH 3/3] Teach the pin inventory the conditional openai-client shape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SSRF pin inventory asserted a literal unconditional pin in the openai-client; the previous commit made that pin conditional for the two person-typed base-URL tags. The guard now asserts the exact ternary — allowlist helper for gateway/admin-key, literal true as the floor — so neither the floor nor the condition can drift silently. --- src/lib/__tests__/ssrf-pin-inventory.test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/__tests__/ssrf-pin-inventory.test.ts b/src/lib/__tests__/ssrf-pin-inventory.test.ts index 6e598849a..b5b7d67c5 100644 --- a/src/lib/__tests__/ssrf-pin-inventory.test.ts +++ b/src/lib/__tests__/ssrf-pin-inventory.test.ts @@ -8,7 +8,8 @@ * A future edit that drops the pin (re-opening the SSRF surface) fails here * instead of shipping silently. * - * The LOCAL AI client is the deliberate exception: it stays CONDITIONAL + * 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 = @@ -26,8 +27,16 @@ const SRC = join(__dirname, ".."); const read = (rel: string) => readFileSync(join(SRC, rel), "utf8"); describe("SSRF requirePublicHost pin inventory", () => { - it("openai-client pins the BYO base-URL outbound unconditionally", () => { - expect(read("ai/openai-client.ts")).toMatch(/requirePublicHost:\s*true/); + // v1.37.30 — openai-client is no longer a blanket pin: the gateway and + // admin-key tags carry a person-typed base URL and route through the + // operator allowlist helper, with `true` as the ternary floor for every + // other tag (codex). We assert the exact conditional shape so a future + // edit can neither drop the floor nor widen the condition silently. + 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/, + ); }); it("anthropic-client pins the BYO base-URL outbound unconditionally", () => {