From 2180ad2f623dd74a0eba75fbee6306cda622cd42 Mon Sep 17 00:00:00 2001 From: Bryandero98 Date: Wed, 2 Sep 2026 07:42:11 -0700 Subject: [PATCH] fix: move the endpoint guard to aiToolkit's public root so services stop deep-importing internal/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `evaluateSecretEndpoint`/`assertSecretEndpoint` — the SSRF/key-exfiltration guard that decides whether a paid API key may be attached to a provider `endpoint` — lived at `aiToolkit/internal/endpointGuard.js`, yet PortOS service modules imported it from that private path. Any toolkit resync or internal reshuffle would have required a manual multi-service migration, with a runtime import failure as the failure mode. Move it to `aiToolkit/endpointGuard.js`, a public peer of `errorDetection.js` — the module that already establishes the "pure toolkit root module, direct-importable and barrel re-exported" shape. `index.js` adds the matching `export *`, so the barrel advertises the surface without any consumer paying for the composition root's route/provider/runner graph to reach one pure URL check. Guard logic and its test are byte-identical to before: same allow/block decisions, same evaluate-vs-assert split, same keyless local-LLM behavior, same `allowCustomEndpoint` opt-in. Fixes #5619 --- server/lib/README.md | 2 +- server/lib/aiToolkit/{internal => }/endpointGuard.js | 7 +++++-- server/lib/aiToolkit/{internal => }/endpointGuard.test.js | 0 server/lib/aiToolkit/index.js | 1 + server/lib/aiToolkit/providers.js | 4 ++-- server/lib/aiToolkit/runner.js | 2 +- server/lib/aiToolkit/validation.js | 2 +- server/lib/validation.js | 2 +- server/services/aiProvider.js | 2 +- server/services/askService.js | 2 +- server/services/localLlmPlayground.js | 2 +- server/services/visionTest.frameGuard.test.js | 2 +- server/services/visionTest.js | 2 +- server/services/voice/llm.js | 2 +- 14 files changed, 18 insertions(+), 14 deletions(-) rename server/lib/aiToolkit/{internal => }/endpointGuard.js (95%) rename server/lib/aiToolkit/{internal => }/endpointGuard.test.js (100%) diff --git a/server/lib/README.md b/server/lib/README.md index f752a63726..22a4cd33f9 100644 --- a/server/lib/README.md +++ b/server/lib/README.md @@ -136,7 +136,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub | Module | Purpose | |---|---| -| `aiToolkit/` | Vendored toolkit (providers + runner + prompts + status). See `aiToolkit/index.js`. | +| `aiToolkit/` | Vendored toolkit (providers + runner + prompts + status). See `aiToolkit/index.js`. `aiToolkit/endpointGuard.js` — a peer of `aiToolkit/errorDetection.js`, not under `internal/` — publicly exports `evaluateSecretEndpoint`/`assertSecretEndpoint`, the SSRF/key-exfiltration guard for provider `endpoint` URLs; PortOS's own `server/services/*` should import both directly from there (also re-exported through `aiToolkit/index.js` for barrel completeness, but that pulls the toolkit's much larger route/provider/runner graph — not worth it for just this guard). | | `aiToolkitState.js` | Module-level singleton for the toolkit instance shared by the `providers`/`runner`/`promptService` shims — `setAIToolkitInstance` / `requireToolkit` (throws `AI_TOOLKIT_NOT_INITIALIZED`) / `getAIToolkitInstance` (no-throw for cleanup paths). | | `antigravity.js` | Antigravity (`agy`) CLI provider helpers — id/sentinel constants (`ANTIGRAVITY_CLI_ID`, `ANTIGRAVITY_CONFIGURED_DEFAULT`, `LEGACY_GEMINI_*`), `isAntigravityCommand`/`isAntigravityCliProvider` predicates, and `ensureAntigravityPrintArgs(args, {model, effort})`/`ensureAntigravityTuiArgs(args, {model, effort})`/`stripAntigravityUnsupportedArgs` argv normalizers. `parseAntigravityModelList(stdout)` parses `agy models` rows — accepts both the modern `\t