mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
* chore(release): open v3.8.13 development cycle Bump 3.8.12 → 3.8.13 across package.json, lockfile, electron/, open-sse/, and docs/reference/openapi.yaml; add the [3.8.13] cycle placeholder to the root CHANGELOG and the 41 i18n mirrors. Integration branch for the v3.8.13 cycle — fixes/features land here via per-issue PRs and it merges to main at release time. * fix(ci): skip auto-deploy when VPS host is unreachable from the runner (#3299) Integrated into release/v3.8.13 * fix(dev): auto-rebuild better-sqlite3 on Node ABI mismatch at dev startup (#3301) Integrated into release/v3.8.13 * feat(api): accept path-scoped API keys on client API routes (#3300) Integrated into release/v3.8.13 * fix(sse): harden against empty responses causing Copilot Chat failures (#3297) Integrated into release/v3.8.13 * fix(api): remove Completions.me rickroll provider (discussion #3293) (#3302) Integrated into release/v3.8.13 * fix(opencode-provider): extract contextLength from live model catalog (#3298) Integrated into release/v3.8.13 * feat(web-cookie): self-service login infrastructure + auto-refresh daemon (#3292) Integrated into release/v3.8.13 * docs(changelog): record the v3.8.13 PRs merged this round (#3292/#3300/#3297/#3298/#3301/#3302/#3299) * fix(auth): harden URL token extraction — drop query-string fallback, gate to client routes (security follow-up to #3300) (#3309) Security follow-up to #3300 — integrated into release/v3.8.13 * docs: rename resolve-issues → review-issues skill references * fix(dashboard): keep no-auth providers visible under 'Show configured only' (#3290) (#3312) no-auth providers (opencode, duckduckgo-web, theoldllm, veoaifree-web) never create a DB connection row so stats.total stays 0, which the configured-only filter treated as 'unconfigured' and hid them — even though they are always usable and appear unconditionally in /v1/models. filterConfiguredProviderEntries now treats displayAuthType === 'no-auth' as configured. Co-authored-by: uniQta <uniQta@users.noreply.github.com> * fix(cli): resolve update paths relative to script + recursive backup (#3295) (#3313) omniroute update always failed on a global install: - getCurrentVersion() read package.json from process.cwd(), which on a global npm/brew install is the user's working dir, not the package root → null → 'Could not determine current version'. - createBackup() resolved bin/ from cwd too, and passed the 'cli' directory to copyFileSync → EISDIR, swallowed by the catch → 'Failed to create backup'. Both now resolve package.json/bin relative to the script via import.meta.url, and the backup uses cpSync({recursive:true}) so the cli/ directory is copied. Co-authored-by: uniQta <uniQta@users.noreply.github.com> * fix(theoldllm): read upstream body once to avoid [502] body-already-read (#3296) (#3314) On the cached-token path the executor never enters the refresh branch, so the same upstream Response was read with .text() twice (token-rejection check + final body). A Response body is single-use, so the second read threw 'Body is unusable: Body has already been read', caught and surfaced as [502]. Read the body once into finalBody and only re-read after a token-rejection refetch. Co-authored-by: onizukashonan14-png <onizukashonan14-png@users.noreply.github.com> * fix(sse): strip leaked internal tool envelopes from streaming output (#3311) Integrated into release/v3.8.13 * fix(sse): expose Claude + Gemini budget tiers in the antigravity catalog (#3184) (#3303) Integrated into release/v3.8.13 (#3184) * fix(catalog): compute combo context_length from known targets only (#3304) Integrated into release/v3.8.13 — live contextLength + known-targets combo context (#3298 follow-up) * chore(i18n): add message keys for proxy UI + vscode/ollama endpoint (#3307) Integrated into release/v3.8.13 — i18n message keys for proxy UI + vscode/ollama * feat(dashboard): i18n the proxy settings UI (#3310) Integrated into release/v3.8.13 — i18n the proxy settings UI * feat(api): model catalog enrichment + MCP model-catalog tools (#3306) Integrated into release/v3.8.13 — model catalog enrichment + MCP model-catalog tools, reconciled with #3309 URL-token hardening * test(catalog): align Antigravity preview-alias test with #3303 budget tiers #3303 added the Gemini `-high`/`-low` budget tiers to ANTIGRAVITY_PUBLIC_MODELS (user-callable on the Antigravity OAuth backend, verified via #3184), but did not update the catalog-route test that asserted `antigravity/gemini-3.1-pro-high` must NOT be exposed. The assertion now reflects the intended behavior — the client-visible budget alias IS surfaced — while keeping the legacy `gemini-claude-*` alias keys unexposed. Caught running the full catalog suite on the merged release HEAD (the #3303 round only ran the antigravity-aliases and usage-hardening files). * docs(changelog): record the 6 PRs merged this review round into v3.8.13 #3306/#3307/#3310 (New Features — VS Code split: catalog+MCP, i18n keys, proxy UI i18n), #3311/#3303/#3304 (Bug Fixes — SSE envelope sanitizer, antigravity budget tiers, combo known-targets context_length). * chore(release): finalize v3.8.13 changelog and cleanup Finalize the v3.8.13 changelog with release date, maintenance notes, and contributor credits. Update MCP docs to reference the correct tool inventory diagram, exclude nested .claude worktrees from ESLint scans, and tighten a response sanitizer type guard. * fix(dashboard): refresh connections after provider auth import (#3320) Integrated into release/v3.8.13 — refresh connections after provider auth import * fix(codex): strip client-only params on native /responses passthrough (#3317) (#3325) A /v1/responses request against the built-in codex/ provider does an openai-responses -> openai-responses passthrough (CodexExecutor.transformRequest returns the body early for _nativeCodexPassthrough). It forwarded client-only fields verbatim and the Codex upstream rejected them with 400 Unsupported parameter: prompt_cache_retention / safety_identifier / user — breaking Factory Droid (which injects all three). The chat-completions path already strips these (base.ts #1884, openai-responses translator #2770) but the passthrough skips translation. Strip the three fields in the shared block before the passthrough return; user is removed unconditionally since Codex /responses always rejects it. Co-authored-by: tycronk20 <tycronk20@users.noreply.github.com> * fix(dashboard): normalize agent-bridge /state response to stop page crash (#3318) (#3326) The Agent Bridge page seeded a well-shaped initialData default then replaced it wholesale with the raw /api/tools/agent-bridge/state response. The route returns { server, agents } but the UI reads { serverState, agentStates, bypassPatterns, mappings }, so serverState became undefined and AgentBridgeServerCard crashed on serverState.running — surfaced as the full-page 'Internal Server Error' boundary (client render error, not a real 5xx). Add a shared normalizeAgentBridgeState() that maps the route shape into the page contract (server.running/certExists -> serverState) and always returns safe defaults (never undefined serverState). Wired into both the SSR loader (page.tsx) and the polling hook. The legacy 'agents' entry shape differs from AgentStateEntry so it is not coerced; full route<->page contract reconciliation (port, upstreamCa, bypassPatterns, mappings, agentStates) is a follow-up. Co-authored-by: tycronk20 <tycronk20@users.noreply.github.com> * docs: VS Code/Ollama endpoints + env & i18n tooling (#3319) Integrated into release/v3.8.13 — VS Code/Ollama docs + env & i18n tooling * feat(provider): test-all endpoint, rate-limit overrides, visibility f… (#3267) Integrated into release/v3.8.13 — provider test-all endpoint, rate-limit overrides, model visibility * feat: auto-combo optimization, playground model dropdown, only-configured toggle (#3322) Integrated into release/v3.8.13 — auto-combo candidate expansion + playground dropdown + only-configured toggle * feat(api): VS Code Copilot Ollama-compatible BYOK endpoint (#3316) Integrated into release/v3.8.13 — VS Code Copilot Ollama-compatible BYOK endpoint (reconciled with #3306/#3309 auth hardening) * chore(release): document #3320 in the v3.8.13 changelog + contributor credits --------- Co-authored-by: Felipe Almeman <4226997+zhiru@users.noreply.github.com> Co-authored-by: Wilson <pedbookmed@gmail.com> Co-authored-by: Hernan Javier Ardila Sanchez <hjasgr@gmail.com> Co-authored-by: Paijo <14921983+oyi77@users.noreply.github.com> Co-authored-by: uniQta <uniQta@users.noreply.github.com> Co-authored-by: onizukashonan14-png <onizukashonan14-png@users.noreply.github.com> Co-authored-by: tycronk20 <tycronk20@users.noreply.github.com> Co-authored-by: Vinayrnani <vinayrnani@gmail.com>
130 lines
5.3 KiB
TypeScript
130 lines
5.3 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { extractApiKey } = await import("../../src/sse/services/auth.ts");
|
|
|
|
function makeRequest(headers: Record<string, string>): Request {
|
|
return new Request("https://omniroute.test/v1/messages", { headers });
|
|
}
|
|
|
|
const ANTHROPIC = { "anthropic-version": "2023-06-01" } as const;
|
|
|
|
test("extractApiKey returns Bearer key when Authorization header is set", () => {
|
|
const req = makeRequest({ Authorization: "Bearer sk-test-bearer" });
|
|
assert.equal(extractApiKey(req), "sk-test-bearer");
|
|
});
|
|
|
|
test("extractApiKey trims surrounding whitespace from Bearer token", () => {
|
|
const req = makeRequest({ Authorization: "Bearer sk-padded-token " });
|
|
assert.equal(extractApiKey(req), "sk-padded-token");
|
|
});
|
|
|
|
test("extractApiKey is case-insensitive on the Authorization header name", () => {
|
|
const req = makeRequest({ authorization: "Bearer sk-lowercase-header" });
|
|
assert.equal(extractApiKey(req), "sk-lowercase-header");
|
|
});
|
|
|
|
test("extractApiKey is case-insensitive on the 'bearer' prefix", () => {
|
|
const req = makeRequest({ Authorization: "bearer sk-lowercase-prefix" });
|
|
assert.equal(extractApiKey(req), "sk-lowercase-prefix");
|
|
});
|
|
|
|
test("extractApiKey falls back to x-api-key when Authorization is absent and anthropic-version is set (#2225)", () => {
|
|
const req = makeRequest({ "x-api-key": "sk-anthropic-native", ...ANTHROPIC });
|
|
assert.equal(extractApiKey(req), "sk-anthropic-native");
|
|
});
|
|
|
|
test("extractApiKey accepts uppercase X-Api-Key header alongside anthropic-version (#2225)", () => {
|
|
const req = makeRequest({ "X-Api-Key": "sk-uppercase-xapikey", ...ANTHROPIC });
|
|
assert.equal(extractApiKey(req), "sk-uppercase-xapikey");
|
|
});
|
|
|
|
test("extractApiKey trims surrounding whitespace from x-api-key value", () => {
|
|
const req = makeRequest({ "x-api-key": " sk-padded-xapikey ", ...ANTHROPIC });
|
|
assert.equal(extractApiKey(req), "sk-padded-xapikey");
|
|
});
|
|
|
|
test("extractApiKey prefers Bearer over x-api-key when both are present (back-compat)", () => {
|
|
const req = makeRequest({
|
|
Authorization: "Bearer sk-bearer-wins",
|
|
"x-api-key": "sk-loser",
|
|
...ANTHROPIC,
|
|
});
|
|
assert.equal(extractApiKey(req), "sk-bearer-wins");
|
|
});
|
|
|
|
test("extractApiKey returns null when neither header is present", () => {
|
|
const req = makeRequest({});
|
|
assert.equal(extractApiKey(req), null);
|
|
});
|
|
|
|
test("extractApiKey returns null when x-api-key contains only whitespace", () => {
|
|
const req = makeRequest({ "x-api-key": " ", ...ANTHROPIC });
|
|
assert.equal(extractApiKey(req), null);
|
|
});
|
|
|
|
test("extractApiKey returns null when Authorization is not a Bearer scheme and x-api-key is absent", () => {
|
|
const req = makeRequest({ Authorization: "Basic <stub-base64>" });
|
|
assert.equal(extractApiKey(req), null);
|
|
});
|
|
|
|
test("extractApiKey falls back to x-api-key when Authorization is a non-Bearer scheme (anthropic-version present)", () => {
|
|
const req = makeRequest({
|
|
Authorization: "Basic <stub-base64>",
|
|
"x-api-key": "stub-fallback-after-basic",
|
|
...ANTHROPIC,
|
|
});
|
|
assert.equal(extractApiKey(req), "stub-fallback-after-basic");
|
|
});
|
|
|
|
test("extractApiKey ignores x-api-key when anthropic-version is missing — protects local-mode non-Anthropic clients", () => {
|
|
const req = makeRequest({ "x-api-key": "placeholder-key" });
|
|
assert.equal(extractApiKey(req), null);
|
|
});
|
|
|
|
test("extractApiKey accepts Anthropic-Version (TitleCase) header", () => {
|
|
const req = makeRequest({
|
|
"x-api-key": "sk-titlecase-version",
|
|
"Anthropic-Version": "2024-10-22",
|
|
});
|
|
assert.equal(extractApiKey(req), "sk-titlecase-version");
|
|
});
|
|
|
|
test("extractApiKey extracts a path-scoped token from /api/v1/vscode/<token>/...", () => {
|
|
const req = new Request("https://omniroute.test/api/v1/vscode/sk-test-path-token/models");
|
|
assert.equal(extractApiKey(req), "sk-test-path-token");
|
|
});
|
|
|
|
test("extractApiKey extracts a path-scoped token from /api/v1/vscode/raw/<token>/...", () => {
|
|
const req = new Request(
|
|
"https://omniroute.test/api/v1/vscode/raw/sk-test-path-token/api/version"
|
|
);
|
|
assert.equal(extractApiKey(req), "sk-test-path-token");
|
|
});
|
|
|
|
test("extractApiKey extracts a path-scoped token from /api/v1/vscode/combos/<token>/...", () => {
|
|
const req = new Request(
|
|
"https://omniroute.test/api/v1/vscode/combos/sk-test-path-token/api/version"
|
|
);
|
|
assert.equal(extractApiKey(req), "sk-test-path-token");
|
|
});
|
|
|
|
test("extractApiKey does NOT extract a query-string token (#3300 security follow-up)", () => {
|
|
// Query-string fallbacks (?token / ?key / ?apiKey / ?api_key) were removed —
|
|
// a credential in the query string leaks into access logs / Referer headers.
|
|
for (const q of ["token", "key", "apiKey", "api_key"]) {
|
|
const req = new Request(`https://omniroute.test/api/v1/models?${q}=sk-test-query-token`);
|
|
assert.equal(extractApiKey(req), null, `?${q}= must not be extracted`);
|
|
}
|
|
});
|
|
|
|
test("extractApiKey skips the path-scoped token when allowUrl is false (management auth)", () => {
|
|
const req = new Request("https://omniroute.test/api/v1/vscode/sk-test-path-token/models");
|
|
assert.equal(extractApiKey(req, { allowUrl: false }), null);
|
|
// Headers still work regardless of allowUrl.
|
|
const withHeader = new Request("https://omniroute.test/api/v1/vscode/sk-test-path-token/models", {
|
|
headers: { Authorization: "Bearer sk-header-wins" },
|
|
});
|
|
assert.equal(extractApiKey(withHeader, { allowUrl: false }), "sk-header-wins");
|
|
});
|