Compare commits

..

3 Commits

Author SHA1 Message Date
diegosouzapw
72844781b5 Merge remote-tracking branch 'origin/release/v3.8.55' into fix/services-ws-proxy-auth 2026-11-18 16:48:38 -03:00
diegosouzapw
1f31d61d27 fix(security): narrow the upgrade verdict with an equality check
The production build program is not strict, so !verdict.allow did not narrow the union and check:build-typecheck reported TS2339 on status/message.
2026-11-18 16:46:23 -03:00
diegosouzapw
0328768396 fix(security): authorize embedded-service WebSocket proxy upgrades
The embedded-services WebSocket proxy (EMBED_WS_PROXY_PORT, default 20131)
tunnelled any upgrade to the target service and added the service's own
Authorization header, without checking who asked. It now applies the same
decision as the HTTP embed route (LOCAL_ONLY + management auth) before it
opens a tunnel:

- the TCP peer must be loopback and carry no reverse-proxy hop header;
- a browser Origin must be one of the dashboard origins (same allow-list
  as the Live dashboard socket);
- the caller needs a dashboard session or a management-scope API key,
  unless dashboard login is disabled (same bar as the HTTP embed route).

A rejected upgrade gets 401/403 and never reaches the service, so the
service credential is only sent on behalf of an authorized caller. Auth
backend errors fail closed (503).

Service bootstrap no longer starts a service with a fixed fallback
credential when its stored key cannot be loaded; the service is skipped
and the on-demand /api/services/<name>/* path reports the key error.
2026-11-18 00:37:52 -03:00
39 changed files with 603 additions and 539 deletions

View File

@@ -450,13 +450,12 @@ jobs:
echo "✅ Published omniroute@$VERSION (dist-tag=$TAG) via Trusted Publishing"
- name: Publish to npm (staged — owner approves with 2FA)
# Only on an explicit request now: Trusted Publishing above is the default. Staging
# also goes through OIDC (Trusted Publishers allow `npm stage publish`); the approve
# step still needs the owner's 2FA.
# Only on an explicit request now: Trusted Publishing below is the default.
if: github.event_name == 'workflow_dispatch' && inputs.publish_mode == 'staged'
env:
VERSION: ${{ needs.publish.outputs.version }}
TAG: ${{ needs.publish.outputs.tag }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -euo pipefail
TARBALL="omniroute-${VERSION}.tgz"
@@ -480,9 +479,6 @@ jobs:
} >> "$GITHUB_STEP_SUMMARY"
echo "✅ Staged omniroute@$VERSION (dist-tag=$TAG) — awaiting owner 'npm stage approve'"
# The one step still on a token: for when Trusted Publishing itself is broken. npm caps
# write tokens at 90 days, so mint a fresh granular token (publish on omniroute, 2FA
# bypass) and set NPM_TOKEN right before dispatching publish_mode=direct.
- name: Publish to npm (DIRECT — emergency fallback)
if: github.event_name == 'workflow_dispatch' && inputs.publish_mode == 'direct'
env:
@@ -602,13 +598,10 @@ jobs:
working-directory: "@omniroute/opencode-plugin"
run: npm test
# Trusted Publishing (OIDC), like the main package: no NODE_AUTH_TOKEN. npm >= 11.5
# detects the job's id-token itself. The Trusted Publisher of this package
# (cheaper-inference/OmniRoute, npm-publish.yml, no environment, "npm publish" allowed)
# was set up on 2026-11-18, after the long-lived NPM_TOKEN expired and v3.8.54's
# plugin publishes answered E404.
- name: Publish @omniroute/opencode-plugin to npm
working-directory: "@omniroute/opencode-plugin"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -euo pipefail
PKG_VERSION=$(node -p "require('./package.json').version")
@@ -728,13 +721,10 @@ jobs:
working-directory: "@omniroute/opencode-plugin-v2"
run: npm test
# Trusted Publishing (OIDC), like the main package: no NODE_AUTH_TOKEN. npm >= 11.5
# detects the job's id-token itself. The Trusted Publisher of this package
# (cheaper-inference/OmniRoute, npm-publish.yml, no environment, "npm publish" allowed)
# was set up on 2026-11-18, after the long-lived NPM_TOKEN expired and v3.8.54's
# plugin publishes answered E404.
- name: Publish @omniroute/opencode-plugin-v2 to npm
working-directory: "@omniroute/opencode-plugin-v2"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -euo pipefail
PKG_VERSION=$(node -p "require('./package.json').version")

View File

@@ -275,7 +275,7 @@ ENV DATA_DIR=/app/data
RUN mkdir -p /app/data && chown node:node /app /app/data
# #13679: default the PUBLISHED image to requiring an API key. A bare
# `docker run -p 20128:20128 … cheaperinference/omniroute` (README/QUICK-START
# `docker run -p 20128:20128 … diegosouzapw/omniroute` (README/QUICK-START
# one-liners) does not pass `--env-file .env`, so without this default the
# anonymous /v1 LLM proxy would be both keyless AND world-reachable on the
# published container. This does NOT change the npm/CLI local-dev default

View File

@@ -87,7 +87,7 @@
[![npm version](https://img.shields.io/npm/v/omniroute?color=cb3837&logo=npm)](https://www.npmjs.com/package/omniroute)
![NPM Monthly](https://img.shields.io/npm/dm/omniroute?label=npm/month&color=cb3837&logo=npm)
[![Docker Hub](https://img.shields.io/docker/v/cheaperinference/omniroute?label=Docker%20Hub&logo=docker&color=2496ED)](https://hub.docker.com/r/cheaperinference/omniroute)
[![Docker Hub](https://img.shields.io/docker/v/diegosouzapw/omniroute?label=Docker%20Hub&logo=docker&color=2496ED)](https://hub.docker.com/r/diegosouzapw/omniroute)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](LICENSE)
![Docker Pulls](https://img.shields.io/docker/pulls/diegosouzapw/omniroute?label=docker%20pulls&logo=docker&color=2496ED)
![Electron Downloads](https://img.shields.io/github/downloads/diegosouzapw/omniroute/total?style=flat&label=electron%20downloads&logo=electron&color=47848F)
@@ -781,7 +781,7 @@ of your shell history. → [CLI Integrations](docs/guides/CLI-INTEGRATIONS.md)
<tr><th align="left">Platform</th><th align="left">Install</th><th align="left">Highlights</th></tr>
<tr><td align="left" nowrap>📦 <b>npm (global)</b></td><td align="left" nowrap><code>npm install -g omniroute</code></td><td align="left">One command, any OS</td></tr>
<tr><td align="left" nowrap>⚡ <b>Bun (global)</b></td><td align="left" nowrap><code>bun add -g omniroute</code></td><td align="left">Same registry tarball, faster installs</td></tr>
<tr><td align="left" nowrap>🐳 <b>Docker</b></td><td align="left" nowrap><code>docker run … cheaperinference/omniroute</code></td><td align="left">Multi-arch <b>AMD64 + ARM64</b></td></tr>
<tr><td align="left" nowrap>🐳 <b>Docker</b></td><td align="left" nowrap><code>docker run … diegosouzapw/omniroute</code></td><td align="left">Multi-arch <b>AMD64 + ARM64</b></td></tr>
<tr><td align="left" nowrap>🖥️ <b>Desktop (Electron)</b></td><td align="left" nowrap><code>npm run electron:build</code></td><td align="left">Native window + system tray — <b>Windows / macOS / Linux</b></td></tr>
<tr><td align="left" nowrap>🎩 <b>Menu-bar (OmniRouteTray)</b></td><td align="left" nowrap><code>brew install --cask zoispag/tap/omniroute-tray</code></td><td align="left">Supervises &amp; auto-updates the server — <b>macOS</b></td></tr>
<tr><td align="left" nowrap>💪 <b>ARM</b></td><td align="left" nowrap>native <code>arm64</code></td><td align="left">Raspberry Pi, ARM servers, Apple Silicon</td></tr>
@@ -1105,7 +1105,7 @@ Use these only for clients that cannot attach `Authorization: Bearer ...`. Heade
```bash
docker run -d --name omniroute --restart unless-stopped --stop-timeout 40 \
-p 127.0.0.1:20128:20128 -v omniroute-data:/app/data cheaperinference/omniroute:latest
-p 127.0.0.1:20128:20128 -v omniroute-data:/app/data diegosouzapw/omniroute:latest
```
`:latest` follows the highest **published** stable SemVer. It does not track git `main`. Pin `:X.Y.Z` for GitOps. See [Docker Release Channels](docs/guides/DOCKER_GUIDE.md#release-channels).The image pins **`OMNIROUTE_MEMORY_MB=1024`**. That is enough for the dashboard and a light chat. **Coding agents** (`POST /v1/responses` from Claude Code, Codex, Grok, …) need a much larger V8 heap or the process `FATAL ERROR`s at ~12 GiB under two overlapping long contexts. Size the container above the heap (native buffers sit outside V8):
@@ -1119,7 +1119,7 @@ docker run -d --name omniroute --restart unless-stopped --stop-timeout 40 \
```bash
docker run -d --name omniroute --restart unless-stopped --stop-timeout 40 \
-e OMNIROUTE_MEMORY_MB=8192 --memory=10g \
-p 127.0.0.1:20128:20128 -v omniroute-data:/app/data cheaperinference/omniroute:latest
-p 127.0.0.1:20128:20128 -v omniroute-data:/app/data diegosouzapw/omniroute:latest
```
Full table: [Docker Guide — runtime RAM](docs/guides/DOCKER_GUIDE.md#runtime-ram-for-coding-agents).
@@ -1338,7 +1338,7 @@ Métricas canônicas em 2026-10-18: **1.976 vídeos únicos** · **20.220.289 vi
<tr><td nowrap><b>Testing</b></td><td>Node.js test runner + Vitest — <b>60,000+ static test declarations</b> across 8,400+ tracked test files (unit, integration, E2E, security, ecosystem)</td></tr>
<tr><td nowrap><b>Platforms</b></td><td>Desktop (Electron) · Android (Termux) · PWA (any browser)</td></tr>
<tr><td nowrap><b>CI/CD</b></td><td>GitHub Actions — auto npm publish + Docker Hub on release</td></tr>
<tr><td nowrap><b>Links</b></td><td><a href="https://omniroute.online">Website</a> · <a href="https://www.npmjs.com/package/omniroute">npm</a> · <a href="https://hub.docker.com/r/cheaperinference/omniroute">Docker Hub</a></td></tr>
<tr><td nowrap><b>Links</b></td><td><a href="https://omniroute.online">Website</a> · <a href="https://www.npmjs.com/package/omniroute">npm</a> · <a href="https://hub.docker.com/r/diegosouzapw/omniroute">Docker Hub</a></td></tr>
</table>
<div align="center">

View File

@@ -207,7 +207,7 @@ docker run -d \
-e JWT_SECRET="$(openssl rand -base64 48)" \
-e API_KEY_SECRET="$(openssl rand -hex 32)" \
-e STORAGE_ENCRYPTION_KEY="$(openssl rand -hex 32)" \
cheaperinference/omniroute:latest
diegosouzapw/omniroute:latest
```
---

View File

@@ -1 +0,0 @@
- **fix(ci):** the OpenCode plugins and the staged release mode publish to npm through Trusted Publishing (OIDC) only; the expired long-lived `NPM_TOKEN` is left solely on the DIRECT emergency fallback ([#20489](https://github.com/cheaper-inference/OmniRoute/pull/20489))

View File

@@ -1 +0,0 @@
- **fix(security):** plugin hooks (`onRequest`/`onResponse`/`onError`) no longer receive the client's `authorization`, `x-api-key` or `proxy-authorization` headers or the API key value; the Plugin SDK and marketplace docs now state that plugins run as ordinary Node.js processes with the OmniRoute user's privileges (`requires.permissions` only selects environment variables), and the plugins page shows a warning to that effect ([#20566](https://github.com/cheaper-inference/OmniRoute/pull/20566))

View File

@@ -0,0 +1 @@
- **fix(security):** the embedded-services WebSocket proxy now authorizes every upgrade like the HTTP embed route (loopback peer, dashboard Origin, dashboard session or management-scope key) before it opens a tunnel with the service credential, and service bootstrap no longer starts a service with a fallback credential when its key cannot be loaded

View File

@@ -1 +0,0 @@
- **chore(docker):** new installs use the Cheaper Inference Docker Hub repository `cheaperinference/omniroute` (Helm chart 0.1.2, the base Kubernetes manifest, the manifest generator, compose, Podman and the docs); `diegosouzapw/omniroute` keeps every release and its pull history, and stays the home of the `:next` channel ([#20490](https://github.com/cheaper-inference/OmniRoute/pull/20490))

View File

@@ -191,7 +191,7 @@ podman run -d --name omniroute \
-e DATA_DIR=/app/data \
-p 20128:20128 \
-v omniroute-data:/app/data \
docker.io/cheaperinference/omniroute:latest
docker.io/diegosouzapw/omniroute:latest
```
For a bind mount that still fails, inspect or repair the shared path from the

View File

@@ -9,7 +9,7 @@ After=omniroute-redis.service
# Use this image after building locally
Image=localhost/omniroute:base
# Or use the fully qualified published image (there is no published :base tag)
# Image=docker.io/cheaperinference/omniroute:latest
# Image=docker.io/diegosouzapw/omniroute:latest
ContainerName=omniroute

View File

@@ -3,7 +3,7 @@ name: omniroute
description: OmniRoute — unified AI proxy/router. One endpoint, many LLM providers, auto-fallback.
type: application
# Chart version — bump on every chart change.
version: 0.1.2
version: 0.1.1
# Default image tag. Overridable with image.tag.
appVersion: "latest"
home: https://github.com/cheaper-inference/OmniRoute

View File

@@ -6,7 +6,7 @@
replicaCount: 1
image:
repository: cheaperinference/omniroute
repository: diegosouzapw/omniroute
# Pin a real SemVer (or a digest) for anything you care about. `latest` only
# moves when a stable release promotes it, so it silently lags merged fixes.
tag: "latest"

View File

@@ -43,7 +43,7 @@ spec:
type: RuntimeDefault
containers:
- name: omniroute
image: cheaperinference/omniroute:latest
image: diegosouzapw/omniroute:latest
imagePullPolicy: IfNotPresent
ports:
- name: http

View File

@@ -23,7 +23,7 @@
services:
omniroute:
image: cheaperinference/omniroute:latest
image: diegosouzapw/omniroute:latest
container_name: omniroute
environment:
- OMNIROUTE_DIRECT_HEADERS_TIMEOUT_MS=${OMNIROUTE_DIRECT_HEADERS_TIMEOUT_MS:-300000}

View File

@@ -8,7 +8,7 @@
# open http://127.0.0.1:20128
#
# No profiles, no build step, no multi-tenant anything.
# Pulls the published image `cheaperinference/omniroute:latest`.
# Pulls the published image `diegosouzapw/omniroute:latest`.
#
# All app ports bind to 127.0.0.1 ONLY by default (REQUIRE_API_KEY ships
# as false). Set APP_BIND_HOST=0.0.0.0 in .env ONLY after you have set
@@ -35,7 +35,7 @@ services:
retries: 3
omniroute:
image: cheaperinference/omniroute:latest
image: diegosouzapw/omniroute:latest
container_name: omniroute
restart: unless-stopped
stop_grace_period: 40s

View File

@@ -624,7 +624,12 @@ This proxy:
- Rewrites HTML responses to inject `<base href>` and normalize absolute paths (`/foo` → `/dashboard/.../embed/foo`)
WebSocket upgrades for the embedded dashboard are handled by a companion server on a
dedicated port (see `src/lib/services/embedWsProxy.ts`).
dedicated port (see `src/lib/services/embedWsProxy.ts`). Every upgrade is authorized
before the tunnel opens, with the same rules as the HTTP embed route: the peer must be
loopback with no reverse-proxy forwarding header, a browser `Origin` must be a dashboard
origin (`LIVE_WS_ALLOWED_ORIGINS` / `LIVE_WS_ALLOWED_HOSTS` extend the loopback
defaults), and the caller needs a dashboard session or a management-scope API key unless
dashboard login is disabled.
**Security:** The embed proxy routes are classified under `LOCAL_ONLY_API_PREFIXES`
and can only be reached from loopback. An attacker who obtains a JWT via a

View File

@@ -50,9 +50,8 @@ Dashboard (/dashboard/plugins)
`plugin.json`.
- **Scanner** — `src/lib/plugins/scanner.ts`: discovers plugins on disk under
the plugin directory.
- **Loader** — `src/lib/plugins/loader.ts`: spawns each plugin in a separate
Node.js child process and brokers hook calls over IPC. The child is not a
sandbox (see "Plugin execution isolation" below).
- **Loader** — `src/lib/plugins/loader.ts`: spawns each plugin in an isolated
child process and brokers hook calls over IPC.
## Marketplace Catalog
@@ -243,14 +242,6 @@ silently falls back to the built-in seed registry and logs a warning.
### Plugin execution isolation
> **Plugins are not sandboxed.** The child is an ordinary Node.js process running
> as the OmniRoute user, with no VM context and no Node.js permission flags, so
> plugin code can read and write any file that user can, run programs and reach
> the network. `requires.permissions` only decides which environment variables
> the child receives; the other permissions are not enforced. Install only
> plugins you trust. The process boundary below contains crashes and hangs; it
> is not a security boundary.
- **Process isolation** — `loadPlugin()` (`src/lib/plugins/loader.ts`) spawns
each plugin in a separate Node.js child process and communicates over IPC.
Hook calls have a timeout with `SIGTERM` → `SIGKILL` escalation.
@@ -266,12 +257,8 @@ silently falls back to the built-in seed registry and logs a warning.
- **Optional integrity pin** — a manifest may declare an `integrity`
(`sha256-<base64>`, SRI format) field. When present, the loader verifies the
entry file hash at load time and refuses to activate on mismatch. It is
opt-in tamper-detection, **not** a security boundary: it does not limit what
a loaded plugin can do.
- **No client credentials in hooks** — the context passed to `onRequest`,
`onResponse` and `onError` has the `authorization`, `x-api-key`,
`proxy-authorization` and `cookie` headers removed, and the API key record carries no key
value (`redactPluginContext()` in `src/lib/plugins/hooks.ts`).
opt-in tamper-detection, **not** a security boundary — loopback-only routing
and the permission model are the real boundaries.
## Manifest (`plugin.json`)
@@ -295,9 +282,7 @@ Validated by `PluginManifestSchema` (`src/lib/plugins/manifest.ts`):
| `integrity` | string? | Optional `sha256-<base64>` entry-file pin |
Permissions are drawn from the enum
`network` / `file-read` / `file-write` / `env` / `exec`. Only `env` has a
runtime effect (a slightly larger environment-variable allowlist for the
child); the others are declarations and are not enforced.
`network` / `file-read` / `file-write` / `env` / `exec`.
## Lifecycle Flow
@@ -366,9 +351,6 @@ The dashboard page at `/dashboard/plugins`
- **Marketplace** — shows the catalog from `GET /api/plugins/marketplace` with a
field to set the custom registry URL.
The page always shows a warning that plugins run with the full privileges of
the OmniRoute process.
A per-plugin config page lives at `/dashboard/plugins/[name]/config`
(`src/app/(dashboard)/dashboard/plugins/[name]/config/page.tsx`).

View File

@@ -48,8 +48,8 @@ Block the request and optionally return a custom response.
```ts
onRequest: (ctx) => {
if (!ctx.headers?.["x-client-team"]) {
return blockRequest({ error: "Missing x-client-team header", status: 400 });
if (!ctx.headers["authorization"]) {
return blockRequest({ error: "Unauthorized", status: 401 });
}
};
```
@@ -76,22 +76,15 @@ onRequest: (ctx) => {
## Plugin Context (`PluginContext`)
| Field | Type | Description |
| ------------ | ------------------------- | --------------------------- |
| `requestId` | `string` | Unique request identifier |
| `model` | `string` | Requested model name |
| `provider` | `string` | Target provider ID |
| `body` | `Record<string, unknown>` | Request body |
| `headers` | `Record<string, string>` | Request headers (see note) |
| `metadata` | `Record<string, unknown>` | Mutable metadata |
| `timestamp` | `number` | Request timestamp |
| `apiKeyInfo` | `object` (optional) | API key metadata (see note) |
The context never carries the client's credentials: the `authorization`, `x-api-key`,
`proxy-authorization` and `cookie` headers are removed (any casing), and `apiKeyInfo` keeps the key's
metadata (such as `id`, `name` and `scopes`) but not the key value or its fingerprint
(`redactPluginContext()` in `src/lib/plugins/hooks.ts`). This applies to `onRequest`,
`onResponse` and `onError`.
| Field | Type | Description |
| ----------- | ------------------------- | ------------------------- |
| `requestId` | `string` | Unique request identifier |
| `model` | `string` | Requested model name |
| `provider` | `string` | Target provider ID |
| `body` | `Record<string, unknown>` | Request body |
| `headers` | `Record<string, string>` | Request headers |
| `metadata` | `Record<string, unknown>` | Mutable metadata |
| `timestamp` | `number` | Request timestamp |
## Manifest (`plugin.json`)
@@ -146,22 +139,17 @@ Or as simple booleans (default priority 100):
## Permission System
Plugins are **not sandboxed**. Each active plugin runs as a separate, ordinary Node.js child
process (`loadPlugin()` in `src/lib/plugins/loader.ts`) under the same operating-system user as
OmniRoute, with no VM context and no Node.js permission flags. Plugin code can use `node:fs`,
`node:child_process`, `fetch` and every other Node.js API: it can read and write any file the
OmniRoute user can (including the data directory), run programs and reach the network.
Plugins run in a sandboxed VM context. Access to external resources requires explicit permissions:
The manifest's `requires.permissions` accepts `network`, `file-read`, `file-write`, `env` and
`exec`, but today only `env` has an effect at runtime:
| Permission | Grants |
| ------------ | ------------------------------------------------------------ |
| `network` | `fetch`, `AbortController`, `Headers`, `Request`, `Response` |
| `file-read` | `fs.readFile`, `fs.readdir`, `fs.stat` |
| `file-write` | `fs.writeFile`, `fs.mkdir`, `fs.rm` |
| `env` | Read-only `process.env` proxy |
| `exec` | `child_process.exec`, `child_process.execSync` |
| Permission | Effect today |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `env` | The plugin process also receives `PORT`, `HOSTNAME`, `TZ` and `TMPDIR`. Without it, it receives only `PATH`, `HOME`, `USER`, `LANG`, `LC_ALL`, `NODE_ENV`, `PLUGIN_ENTRY` and `PLUGIN_NAME` (plus `SystemRoot` and `windir` on Windows). |
| `network`, `file-read`, `file-write`, `exec` | None. They are declarations only: nothing is blocked when they are missing. |
Installing a plugin is like installing any other program on the host. Install only plugins whose
source you trust.
Without a permission, the corresponding globals are simply not available in the sandbox.
## Config Schema
@@ -229,7 +217,7 @@ export default definePlugin({
name: "rate-limiter",
priority: 10,
onRequest: async (ctx) => {
const key = ctx.apiKeyInfo?.id || "anonymous";
const key = ctx.headers["x-api-key"] || "anonymous";
const now = Date.now();
const window = 60000; // 1 minute
const maxRequests = 100;

View File

@@ -23,10 +23,10 @@ npm install -g omniroute
### Option B: Docker
```bash
docker run -d --name omniroute -p 20128:20128 cheaperinference/omniroute:latest
docker run -d --name omniroute -p 20128:20128 diegosouzapw/omniroute:latest
```
`:latest` is the highest **published** stable SemVer. It does **not** track git `main`. Pin `cheaperinference/omniroute:X.Y.Z` for GitOps. See [Image Tags / Release Channels](../guides/DOCKER_GUIDE.md#release-channels).
`:latest` is the highest **published** stable SemVer. It does **not** track git `main`. Pin `diegosouzapw/omniroute:X.Y.Z` for GitOps. See [Image Tags / Release Channels](../guides/DOCKER_GUIDE.md#release-channels).
### Option C: From Source

View File

@@ -117,7 +117,7 @@ you need to change them.
docker compose -f docker-compose.selfhost.yml up -d
```
Pulls `cheaperinference/omniroute:latest` (multi-arch AMD64 + ARM64, ~250 MB) and
Pulls `diegosouzapw/omniroute:latest` (multi-arch AMD64 + ARM64, ~250 MB) and
`redis:8.6.5-alpine`, starts both, and waits for Redis to be healthy before
the app boots.

View File

@@ -44,7 +44,7 @@ docker run -d \
--stop-timeout 40 \
-p 20128:20128 \
-v omniroute-data:/app/data \
cheaperinference/omniroute:latest
diegosouzapw/omniroute:latest
```
## With Environment File
@@ -60,7 +60,7 @@ docker run -d \
--env-file .env \
-p 20128:20128 \
-v omniroute-data:/app/data \
cheaperinference/omniroute:latest
diegosouzapw/omniroute:latest
```
## Docker Compose
@@ -342,7 +342,7 @@ Size **cgroup `--memory` above the heap** — native buffers, SQLite, and compre
```bash
docker run -d --name omniroute --restart unless-stopped --stop-timeout 40 \
-e OMNIROUTE_MEMORY_MB=8192 --memory=10g \
-p 127.0.0.1:20128:20128 -v omniroute-data:/app/data cheaperinference/omniroute:latest
-p 127.0.0.1:20128:20128 -v omniroute-data:/app/data diegosouzapw/omniroute:latest
```
## Critical Environment Variables
@@ -398,14 +398,14 @@ runtime environment variable.
### Pre-built root image + runtime subpath
Published `cheaperinference/omniroute:*` images are built for the domain root. You can still
Published `diegosouzapw/omniroute:*` images are built for the domain root. You can still
set `OMNIROUTE_BASE_PATH` at runtime; the container patches the bundle once on startup.
Pair it with the matching public origin:
```yaml
services:
omniroute:
image: cheaperinference/omniroute:latest
image: diegosouzapw/omniroute:latest
environment:
OMNIROUTE_BASE_PATH: /omniroute
NEXT_PUBLIC_BASE_URL: https://myhostname.example.com/omniroute
@@ -446,7 +446,7 @@ OmniRoute can be securely exposed using Caddy's automatic SSL provisioning. Ensu
```yaml
services:
omniroute:
image: cheaperinference/omniroute:latest
image: diegosouzapw/omniroute:latest
container_name: omniroute
restart: unless-stopped
volumes:
@@ -496,17 +496,10 @@ Endpoint tunnel panels (Cloudflare, Tailscale, ngrok) can be shown or hidden fro
## Image Tags
| Image | Tag | Size | Description |
| ---------------------------- | -------- | ------ | ---------------------------------------------------- |
| `cheaperinference/omniroute` | `latest` | ~250MB | Highest **published** stable SemVer (not git `main`) |
| `cheaperinference/omniroute` | `3.8.54` | ~250MB | Pin this class of tag for GitOps |
The same images are published to three repositories, with the same per-architecture digests:
`cheaperinference/omniroute` (Docker Hub, the Cheaper Inference organization, from 3.8.53 on),
`ghcr.io/cheaper-inference/omniroute` and the legacy `diegosouzapw/omniroute`, which keeps its
pull history and still receives every release. Existing `diegosouzapw/omniroute` deployments
keep updating; switching the image name is optional. The `:next` / `:next-web` pre-release
channel below is published to `diegosouzapw/omniroute` and GHCR only.
| Image | Tag | Size | Description |
| ------------------------ | -------- | ------ | ---------------------------------------------------- |
| `diegosouzapw/omniroute` | `latest` | ~250MB | Highest **published** stable SemVer (not git `main`) |
| `diegosouzapw/omniroute` | `3.8.0` | ~250MB | Pin this class of tag for GitOps |
Multi-platform manifest: `linux/amd64` + `linux/arm64` native (Apple Silicon, AWS Graviton, Raspberry Pi). Docker selects the matching architecture automatically; pass `--platform linux/amd64` if you need to force AMD64 emulation on ARM hosts.
@@ -568,7 +561,7 @@ docker image inspect diegosouzapw/omniroute:next --format '{{index .RepoDigests
Before testing, back up the OmniRoute data volume or bind-mounted data directory. To roll back, restore the previously used stable version or digest and recreate the container:
```bash
docker pull cheaperinference/omniroute:<stable-version>
docker pull diegosouzapw/omniroute:<stable-version>
docker compose up -d
```

View File

@@ -472,7 +472,7 @@ see [`docs/guides/KIRO_SETUP.md`](./KIRO_SETUP.md).
2. **Permanent fix:** Bind to IPv4 explicitly by using `-p 127.0.0.1:20128:20128` in your `docker run` command:
```bash
docker run -d --name omniroute --restart unless-stopped --stop-timeout 40 \
-p 127.0.0.1:20128:20128 -v omniroute-data:/app/data cheaperinference/omniroute:latest
-p 127.0.0.1:20128:20128 -v omniroute-data:/app/data diegosouzapw/omniroute:latest
```
This forces the IPv4 bind and also avoids exposing the proxy on all host interfaces.

View File

@@ -72,8 +72,6 @@ docker rm omniroute
docker volume rm omniroute-data
# (Optional) Remove the image
docker rmi cheaperinference/omniroute:latest
# Older installs pulled the legacy name:
docker rmi diegosouzapw/omniroute:latest
```

View File

@@ -354,7 +354,7 @@ Helm:
```bash
# Kustomize: pin a real tag rather than relying on :latest
kubectl -n omniroute set image deploy/omniroute omniroute=cheaperinference/omniroute:3.8.54
kubectl -n omniroute set image deploy/omniroute omniroute=diegosouzapw/omniroute:3.8.51
# Helm
helm upgrade omniroute deploy/helm/omniroute -n omniroute --reuse-values \

View File

@@ -135,7 +135,7 @@ EOF
### 2.3 Start the container
```bash
docker pull cheaperinference/omniroute:latest
docker pull diegosouzapw/omniroute:latest
docker run -d \
--name omniroute \
@@ -143,7 +143,7 @@ docker run -d \
--env-file /opt/omniroute/.env \
-p 20128:20128 \
-v omniroute-data:/app/data \
cheaperinference/omniroute:latest
diegosouzapw/omniroute:latest
```
### 2.4 Verify that it is running
@@ -302,13 +302,13 @@ curl -sI https://llms.seudominio.com/health
### Upgrade to a new version
```bash
docker pull cheaperinference/omniroute:latest
docker pull diegosouzapw/omniroute:latest
docker stop omniroute && docker rm omniroute
docker run -d --name omniroute --restart unless-stopped \
--env-file /opt/omniroute/.env \
-p 20128:20128 \
-v omniroute-data:/app/data \
cheaperinference/omniroute:latest
diegosouzapw/omniroute:latest
```
### View logs

View File

@@ -70,7 +70,7 @@ docker run -d --name omniroute \
-p 20128:20128 \
-v omniroute-data:/app/data \
-e ENABLE_CC_COMPATIBLE_PROVIDER=true \
cheaperinference/omniroute:latest
diegosouzapw/omniroute:latest
```
After restarting, the dashboard exposes an **Add Claude Code Compatible** option in

View File

@@ -2,10 +2,8 @@
import { useState, useEffect, useCallback } from "react";
import { PageHeader } from "@omniroute/ui-kit/page-header";
import { Alert } from "@omniroute/ui-kit/alert";
import { Card, Button, EmptyState } from "@/shared/components";
import Badge from "@/shared/components/Badge";
import Icon from "@/shared/components/Icon";
import { useNotificationStore } from "@/store/notificationStore";
import { useConfirmDialog } from "@/shared/hooks/useConfirmDialog";
import { useTranslations } from "next-intl";
@@ -114,13 +112,6 @@ export default function PluginsPage() {
</Button>
}
/>
<Alert
variant="warning"
dismissible={false}
icon={<Icon name="warning" size={18} />}
title={t("privilegesWarningTitle")}
description={t("privilegesWarningBody")}
/>
{plugins.length === 0 ? (
<EmptyState title={t("noPlugins")} description={t("noPluginsDescription")} />
) : (

View File

@@ -13434,8 +13434,6 @@
"scanForPlugins": "Scan for Plugins",
"noPlugins": "No plugins installed",
"noPluginsDescription": "Place plugin directories in ~/.omniroute/plugins/ and click Scan.",
"privilegesWarningTitle": "Plugins run with full privileges",
"privilegesWarningBody": "A plugin runs as a regular Node.js process with the same access as OmniRoute: it can read files, run programs and use the network, whatever permissions its manifest declares. Install only plugins you trust.",
"activate": "Activate",
"deactivate": "Deactivate",
"uninstall": "Uninstall",

View File

@@ -344,7 +344,7 @@ export function defaultSpec(target: DeployTargetKind): DeploySpec {
namespace: "omniroute",
releaseName: "omniroute",
image: {
repository: "cheaperinference/omniroute",
repository: "diegosouzapw/omniroute",
tag: "latest",
pullPolicy: "IfNotPresent" as const,
},

View File

@@ -231,55 +231,11 @@ export interface PluginContext {
/** Client request headers available at the call site. Optional — not all callers
* have access to headers (e.g. internal triggers, retries). Exposed so
* observability/trace-export plugins can read request-scoped context sent by the
* client (trace ids, correlation ids, session markers). Credential headers are removed
* before a hook sees the context (see redactPluginContext). */
* client (trace ids, correlation ids, session markers). */
headers?: Record<string, string | string[] | undefined>;
metadata: Record<string, unknown>;
}
// ── Credential redaction ──
// Plugins are third-party code running as an ordinary Node process with the OmniRoute
// user's privileges, so anything in the hook context is readable by them. The client's
// credentials never go there: the request pipeline keeps its own (unmodified) copy.
const CREDENTIAL_HEADER_NAMES: ReadonlySet<string> = new Set([
"authorization",
"x-api-key",
"proxy-authorization",
// The dashboard session token travels in a cookie.
"cookie",
]);
/** API key record fields that carry the key itself or a fingerprint of it. */
const API_KEY_SECRET_FIELDS: ReadonlySet<string> = new Set(["key", "apiKey", "rawKey", "keyHash"]);
function omitFields(
record: Record<string, unknown>,
shouldOmit: (field: string) => boolean
): Record<string, unknown> {
return Object.fromEntries(Object.entries(record).filter(([field]) => !shouldOmit(field)));
}
/**
* Copy of a hook context without the client's credentials: drops the `authorization`,
* `x-api-key`, `proxy-authorization` and `cookie` headers (any casing) and the key value/fingerprint
* from the API key record. The input is never mutated.
*/
function redactPluginContext<T extends PluginContext>(ctx: T): T {
const redacted: T = { ...ctx };
if (ctx.headers && typeof ctx.headers === "object") {
redacted.headers = omitFields(ctx.headers, (name) =>
CREDENTIAL_HEADER_NAMES.has(name.toLowerCase())
) as PluginContext["headers"];
}
if (ctx.apiKeyInfo && typeof ctx.apiKeyInfo === "object") {
redacted.apiKeyInfo = omitFields(ctx.apiKeyInfo as Record<string, unknown>, (field) =>
API_KEY_SECRET_FIELDS.has(field)
);
}
return redacted;
}
export interface PluginResult {
blocked?: boolean;
response?: unknown;
@@ -374,7 +330,7 @@ export async function runOnRequest(ctx: PluginContext): Promise<PluginResult> {
// When no plugins exist, avoid lazy loading arbitrary plugin code in this request.
if (!canInitializeRequestPlugins()) return {};
await ensurePluginsLoaded();
return emitHookBlocking("onRequest", redactPluginContext(ctx));
return emitHookBlocking("onRequest", ctx);
}
/**
@@ -383,11 +339,10 @@ export async function runOnRequest(ctx: PluginContext): Promise<PluginResult> {
export async function runOnResponse(ctx: PluginContext, response: unknown): Promise<unknown> {
let currentResponse = response;
const list = hooks.get("onResponse") || [];
const hookCtx = redactPluginContext(ctx);
for (const reg of list) {
assertPluginHandlerAllowed();
try {
const result = await reg.handler({ ...hookCtx, response: currentResponse });
const result = await reg.handler({ ...ctx, response: currentResponse });
if (
result !== undefined &&
result !== null &&
@@ -408,7 +363,7 @@ export async function runOnResponse(ctx: PluginContext, response: unknown): Prom
* Run onError hooks — fire-and-forget notification.
*/
export async function runOnError(ctx: PluginContext, error: Error): Promise<void> {
await emitHook("onError", { ...redactPluginContext(ctx), error });
await emitHook("onError", { ...ctx, error });
}
/**

View File

@@ -186,6 +186,23 @@ function buildSpawnArgsFactory(
return () => cliproxySpawnArgs(cfg.port, apiKey);
}
/**
* The service's own credential (API key / admin token), "" when it needs none,
* or null when it cannot be loaded. A null key means the service is not started:
* a guessable stand-in would be worse than no service, and the on-demand
* /api/services/<tool>/* path reports the key error to the operator.
*/
async function loadServiceApiKey(cfg: ServiceEntry): Promise<string | null> {
if (!cfg.needsApiKey) return "";
try {
return await getOrCreateApiKey(cfg.tool);
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : String(err);
console.warn(`[Services] Not supervising ${cfg.tool}: its API key is unavailable. ${msg}`);
return null;
}
}
export async function bootstrapEmbeddedServices(): Promise<void> {
for (const cfg of SERVICES) {
if (getSupervisor(cfg.tool)) continue;
@@ -193,9 +210,8 @@ export async function bootstrapEmbeddedServices(): Promise<void> {
const row = await getVersionManagerTool(cfg.tool);
if (!row || row.status === "not_installed") continue;
const apiKey = cfg.needsApiKey
? await getOrCreateApiKey(cfg.tool).catch(() => "placeholder")
: "";
const apiKey = await loadServiceApiKey(cfg);
if (apiKey === null) continue;
// CLIProxyAPI's generated key is management-only; /v1/models uses its dedicated data-plane key.
const modelSyncApiKey =
cfg.tool === "cliproxy"

View File

@@ -13,8 +13,15 @@
* - Target host is always 127.0.0.1 and port comes from the registry — never
* from user input. No SSRF risk.
* - Server binds to 127.0.0.1 only (loopback) unless EMBED_WS_PROXY_HOST
* is set explicitly. The OmniRoute LOCAL_ONLY rule is enforced at the
* dashboard layer; the proxy itself is loopback-only as defence-in-depth.
* (or LIVE_WS_HOST) is set explicitly.
* - Every upgrade is authorized before the tunnel opens
* (authorizeEmbedWsUpgrade), with the same decision as the HTTP embed route
* (LOCAL_ONLY + management auth, Hard Rule #17): the TCP peer must be
* loopback with no reverse-proxy hop header, a browser Origin must be one of
* the dashboard origins, and the caller must hold a dashboard session or a
* management-scope API key (unless dashboard login is disabled). A rejected
* upgrade never reaches the service, so the injected service credential is
* only ever sent on behalf of an authorized caller. Errors fail closed.
* - Max 50 concurrent connections per service. The 51st request receives 503.
* - Idle timeout: 5 minutes without any data → both sockets are destroyed.
* - Hop-by-hop headers cookie/authorization/origin are stripped from the
@@ -27,6 +34,13 @@ import type { IncomingMessage } from "node:http";
import { getSupervisor } from "./registry";
import { getOrCreateApiKey } from "./apiKey";
import { getApiKeyMetadata } from "@/lib/db/apiKeys";
import { hasProxyHopHeader } from "@/server/authz/proxyHeaders";
import { isLoopbackHost } from "@/server/authz/routeGuard";
import { isOriginAllowed } from "@/server/ws/liveServerAllowList";
import { hasManageScope } from "@/shared/constants/managementScopes";
import { isAuthRequired, isDashboardSessionAuthenticated } from "@/shared/utils/apiAuth";
import { extractApiKey, isValidApiKey } from "@/sse/services/auth";
import {
attachRequestStreamGuards,
installProcessCrashGuard,
@@ -129,7 +143,98 @@ function buildUpstreamHeaders(rawHeaders: string[], port: number, apiKey: string
return lines;
}
export type EmbedWsUpgradeVerdict =
| { allow: true; via: "anonymous" | "dashboard_session" | "management_key" }
| { allow: false; status: number; message: string };
function deny(status: number, message: string): EmbedWsUpgradeVerdict {
return { allow: false, status, message };
}
/** True when the upgrade's real TCP peer is this machine and no proxy hop relayed it. */
function isLocalUpgradePeer(req: IncomingMessage): boolean {
if (hasProxyHopHeader(req.headers)) return false;
return isLoopbackHost(req.socket?.remoteAddress ?? null);
}
/**
* A browser always sends Origin on a WebSocket upgrade; it must be one of the
* dashboard origins (same allow-list as the Live dashboard socket:
* LIVE_WS_ALLOWED_ORIGINS / LIVE_WS_ALLOWED_HOSTS on top of the loopback
* defaults). A client without Origin is not a browser page; it still has to be
* local and authenticated.
*/
function isUpgradeOriginAllowed(origin: string | string[] | undefined): boolean {
if (origin === undefined) return true;
if (typeof origin !== "string" || origin.length === 0) return false;
return isOriginAllowed(origin, process.env);
}
function toHeaders(headers: IncomingMessage["headers"]): Headers {
const out = new Headers();
for (const [name, value] of Object.entries(headers)) {
if (typeof value === "string") out.set(name, value);
else if (Array.isArray(value)) {
out.set(name, value.join(name.toLowerCase() === "cookie" ? "; " : ", "));
}
}
return out;
}
/**
* Decide whether an upgrade may open a tunnel. Mirrors the management policy the
* HTTP embed route (`/dashboard/providers/services/<name>/embed/`) goes through:
* loopback only, then anonymous when dashboard login is off, otherwise a
* dashboard session or an API key with a management scope. Header-only
* credentials; a URL-borne token never counts.
*/
export async function authorizeEmbedWsUpgrade(
req: IncomingMessage
): Promise<EmbedWsUpgradeVerdict> {
if (!isLocalUpgradePeer(req)) {
return deny(403, "The embedded service WebSocket proxy only accepts local connections");
}
if (!isUpgradeOriginAllowed(req.headers.origin)) {
return deny(403, "Origin not allowed");
}
const authRequest = {
url: "http://127.0.0.1/dashboard/providers/services/embed-ws",
method: "GET",
headers: toHeaders(req.headers),
};
try {
if (!(await isAuthRequired(authRequest, { loopback: true }))) {
return { allow: true, via: "anonymous" };
}
if (await isDashboardSessionAuthenticated(authRequest)) {
return { allow: true, via: "dashboard_session" };
}
const apiKey = extractApiKey(authRequest, { allowUrl: false });
if (apiKey && (await isValidApiKey(apiKey))) {
const meta = await getApiKeyMetadata(apiKey);
if (meta && hasManageScope(meta.scopes ?? [])) {
return { allow: true, via: "management_key" };
}
}
return apiKey ? deny(403, "Invalid management token") : deny(401, "Authentication required");
} catch {
return deny(503, "Authentication backend unavailable");
}
}
async function proxyUpgrade(req: IncomingMessage, socket: net.Socket, head: Buffer): Promise<void> {
// Authorize before anything else: an unauthorized caller learns nothing about
// the registered services and never gets a tunnel carrying the service key.
const verdict = await authorizeEmbedWsUpgrade(req);
// `=== false`, not `!verdict.allow`: the production build program is not strict, and
// only the equality check narrows the verdict union there.
if (verdict.allow === false) {
writeError(socket, verdict.status, verdict.message);
return;
}
const rawUrl = req.url ?? "/";
const match = PATH_RE.exec(rawUrl.split("?")[0]);
@@ -245,13 +350,13 @@ export function resolveEmbedWsHost(): string {
* Start the embed WebSocket proxy server.
* Idempotent — safe to call multiple times.
*/
export function initEmbedWsProxy(): void {
export function initEmbedWsProxy(): http.Server | undefined {
// Safety net: a client aborting a connection can emit `Error: aborted`/
// ECONNRESET on the request stream; without this the single missed listener
// becomes an uncaughtException that kills the server. Benign aborts are
// swallowed; genuine errors still crash loudly (#fix-dev-server-aborted).
installProcessCrashGuard();
if (globalThis.__omnirouteEmbedWsStarted) return;
if (globalThis.__omnirouteEmbedWsStarted) return undefined;
const host = resolveEmbedWsHost();
const port = parseInt(process.env.EMBED_WS_PROXY_PORT ?? String(DEFAULT_PORT), 10);
@@ -284,6 +389,8 @@ export function initEmbedWsProxy(): void {
globalThis.__omnirouteEmbedWsStarted = true;
console.log(`[EmbedWsProxy] Listening on ${host}:${port}`);
});
return server;
}
// ─── Exported for testing ────────────────────────────────────────────────────

View File

@@ -1,53 +0,0 @@
// npm publishing goes through Trusted Publishing (OIDC) only. The long-lived NPM_TOKEN expired
// in silence (npm caps write tokens at 90 days) and the v3.8.54 plugin publishes failed with
// E404 because the plugin jobs still sent it; the Trusted Publisher for both plugins was set up
// on 2026-11-18 and @omniroute/opencode-plugin@0.2.2 / -v2@0.1.1 shipped through OIDC. The
// only step left on a token is the DIRECT emergency fallback of `stage-npm`, which exists for
// the case where Trusted Publishing itself is broken and needs a freshly minted token.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
import YAML from "yaml";
const root = fileURLToPath(new URL("../../../", import.meta.url));
const workflow = YAML.parse(readFileSync(join(root, ".github/workflows/npm-publish.yml"), "utf8"));
const DIRECT_FALLBACK = "Publish to npm (DIRECT — emergency fallback)";
function stepsUsingNpmToken() {
const found = [];
for (const [jobName, job] of Object.entries(workflow.jobs)) {
for (const step of job.steps || []) {
if (JSON.stringify(step).includes("secrets.NPM_TOKEN"))
found.push(`${jobName} → ${step.name}`);
}
}
return found;
}
test("only the DIRECT emergency fallback still reads the NPM_TOKEN secret", () => {
assert.deepEqual(stepsUsingNpmToken(), [`stage-npm → ${DIRECT_FALLBACK}`]);
});
for (const jobName of ["publish-opencode-plugin", "publish-opencode-plugin-v2"]) {
test(`${jobName} publishes through OIDC: id-token write, no auth token on the publish step`, () => {
const job = workflow.jobs[jobName];
assert.equal(job.permissions["id-token"], "write");
const publish = job.steps.find((s) => /^Publish @omniroute\//.test(s.name || ""));
assert.ok(publish, `${jobName} has a publish step`);
assert.equal(publish.env?.NODE_AUTH_TOKEN, undefined);
assert.match(publish.run, /npm publish --provenance --access public/);
});
}
test("stage-npm staged mode publishes through OIDC as well", () => {
const job = workflow.jobs["stage-npm"];
assert.equal(job.permissions["id-token"], "write");
const staged = job.steps.find((s) => (s.name || "").startsWith("Publish to npm (staged"));
assert.ok(staged, "stage-npm has the staged step");
assert.equal(staged.env?.NODE_AUTH_TOKEN, undefined);
assert.match(staged.run, /npm stage publish/);
});

View File

@@ -216,29 +216,3 @@ test("generated ConfigMap keys match the committed ConfigMap", () => {
"the dashboard would ship a different env surface than the committed manifests"
);
});
// The default image is the Cheaper Inference Docker Hub repository; the Helm chart and the
// static base manifest point at the same name, so the three ways to deploy agree.
// diegosouzapw/omniroute still receives every release (legacy name, same digests).
test("default image is cheaperinference/omniroute in the generator, the Helm chart and the base manifest", () => {
for (const target of ["local", "vps"] as const) {
const spec = defaultSpec(target);
assert.equal(spec.image.repository, "cheaperinference/omniroute");
const deployment = ofKind(docsFor(spec), "Deployment") as {
spec?: { template?: { spec?: { containers?: { image?: string }[] } } };
};
assert.equal(
deployment.spec?.template?.spec?.containers?.[0]?.image,
`cheaperinference/omniroute:${spec.image.tag}`
);
}
const values = yamlLoad(
fs.readFileSync(path.join(REPO_ROOT, "deploy/helm/omniroute/values.yaml"), "utf8")
) as { image?: { repository?: string } };
assert.equal(values.image?.repository, "cheaperinference/omniroute");
const base = fs.readFileSync(
path.join(REPO_ROOT, "deploy/kubernetes/base/deployment.yaml"),
"utf8"
);
assert.match(base, /image: cheaperinference\/omniroute:latest/);
});

View File

@@ -1,176 +0,0 @@
// Plugin hooks must not receive the client's credentials. A plugin is third-party code
// running as a plain Node child process, so whatever the hook context carries is fully
// readable by it. The request headers handed to onRequest/onResponse/onError must not
// include `authorization`, `x-api-key`, `proxy-authorization` or `cookie` (any casing), and the
// API key record must not carry the key itself — only its id/name/scopes-style metadata.
import { test, afterEach } from "node:test";
import assert from "node:assert/strict";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
const { registerHook, unregisterHooks, runOnResponse, runOnError } =
await import("../../src/lib/plugins/hooks.ts");
const { runPluginOnRequestHook } =
await import("../../open-sse/handlers/chatCore/pluginOnRequest.ts");
const { loadPlugin } = await import("../../src/lib/plugins/loader.ts");
const SECRET = "sk-client-secret-value-0001";
const CREDENTIAL_HEADERS = ["authorization", "x-api-key", "proxy-authorization", "cookie"];
function clientHeaders(): Record<string, string> {
return {
Authorization: `Bearer ${SECRET}`,
"X-Api-Key": SECRET,
"proxy-authorization": `Basic ${SECRET}`,
Cookie: `auth_token=${SECRET}; theme=dark`,
"x-trace-id": "trace-123",
"content-type": "application/json",
};
}
function apiKeyRecord() {
return {
id: "key-id-1",
name: "ci key",
scopes: ["chat"],
noLog: false,
key: SECRET,
keyHash: "fingerprint-of-the-key",
};
}
function assertNoCredentials(seen: unknown) {
const ctx = seen as { headers?: Record<string, unknown>; apiKeyInfo?: Record<string, unknown> };
assert.ok(ctx, "expected the hook to run");
const headerNames = Object.keys(ctx.headers ?? {}).map((h) => h.toLowerCase());
for (const name of CREDENTIAL_HEADERS) {
assert.equal(headerNames.includes(name), false, `hook received the ${name} header`);
}
assert.equal(ctx.headers?.["x-trace-id"], "trace-123", "non-credential headers stay visible");
assert.equal(ctx.apiKeyInfo?.id, "key-id-1");
assert.equal(ctx.apiKeyInfo?.name, "ci key");
assert.deepEqual(ctx.apiKeyInfo?.scopes, ["chat"]);
assert.equal("key" in (ctx.apiKeyInfo ?? {}), false, "hook received the API key value");
assert.equal("keyHash" in (ctx.apiKeyInfo ?? {}), false, "hook received the key fingerprint");
assert.equal(JSON.stringify(seen).includes(SECRET), false, "the client secret reached the hook");
}
const registered: string[] = [];
afterEach(() => {
for (const name of registered.splice(0)) unregisterHooks(name);
});
test("a real plugin process's onRequest hook never sees the client's credentials", async (t) => {
const pluginDir = await mkdtemp(join(tmpdir(), "omniroute-plugin-cred-"));
const entryPoint = join(pluginDir, "index.mjs");
await writeFile(
entryPoint,
`export async function onRequest(ctx) {
return { body: { seen: { headers: ctx.headers ?? null, apiKeyInfo: ctx.apiKeyInfo ?? null } } };
}
`,
"utf-8"
);
const loaded = await loadPlugin(entryPoint, {
name: "credential-probe",
version: "1.0.0",
license: "MIT",
main: "index.mjs",
source: "local",
tags: [],
requires: { permissions: [] },
hooks: { onRequest: true, onResponse: false, onError: false },
skills: [],
enabledByDefault: false,
configSchema: {},
} as unknown as Parameters<typeof loadPlugin>[1]);
t.after(async () => {
loaded.cleanup();
await rm(pluginDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
});
registerHook("onRequest", "credential-probe", loaded.plugin.onRequest as never);
registered.push("credential-probe");
const headers = clientHeaders();
const gate = await runPluginOnRequestHook({
requestId: "req-cred-1",
body: { messages: [{ role: "user", content: "hi" }] },
model: "gpt-x",
provider: "openai",
apiKeyInfo: apiKeyRecord(),
headers,
});
assert.equal(gate.blocked, false);
if (gate.blocked) return;
const body = gate.body as { seen?: unknown } | undefined;
assertNoCredentials(body?.seen);
// The caller's own header record is not mutated: the request pipeline still needs it.
assert.equal(headers.Authorization, `Bearer ${SECRET}`);
assert.equal(headers["X-Api-Key"], SECRET);
});
test("onResponse hooks never see the client's credentials", async () => {
let seen: unknown;
registerHook("onResponse", "credential-probe-response", async (ctx: unknown) => {
seen = ctx;
});
registered.push("credential-probe-response");
await runOnResponse(
{
requestId: "req-cred-2",
body: {},
model: "gpt-x",
provider: "openai",
apiKeyInfo: apiKeyRecord(),
headers: clientHeaders(),
metadata: {},
},
{ status: 200 }
);
assertNoCredentials(seen);
});
test("onError hooks never see the client's credentials", async () => {
let seen: unknown;
registerHook("onError", "credential-probe-error", async (ctx: unknown) => {
seen = ctx;
});
registered.push("credential-probe-error");
await runOnError(
{
requestId: "req-cred-3",
body: {},
model: "gpt-x",
provider: "openai",
apiKeyInfo: apiKeyRecord(),
headers: clientHeaders(),
metadata: {},
},
new Error("upstream failed")
);
assertNoCredentials(seen);
});
test("a context without headers or API key record still reaches the hook unchanged", async () => {
let seen: Record<string, unknown> | undefined;
registerHook("onError", "credential-probe-empty", async (ctx: unknown) => {
seen = ctx as Record<string, unknown>;
});
registered.push("credential-probe-empty");
await runOnError(
{ requestId: "req-cred-4", body: {}, model: "m", provider: "p", metadata: {} },
new Error("x")
);
assert.ok(seen);
assert.equal(seen!.headers, undefined);
assert.equal(seen!.apiKeyInfo, undefined);
assert.equal(seen!.requestId, "req-cred-4");
});

View File

@@ -38,7 +38,7 @@ test("#8497 Podman guide separates local engines from Podman Machine", () => {
assert.match(localGuidance, /podman unshare chown 1000:1000 \.\/data/);
assert.doesNotMatch(machineGuidance, /podman unshare chown/);
assert.match(machineGuidance, /remote client/);
assert.match(machineGuidance, /docker\.io\/cheaperinference\/omniroute:latest/);
assert.match(machineGuidance, /docker\.io\/diegosouzapw\/omniroute:latest/);
});
test("#8497 Quadlet is Linux/systemd-only and generated units are not enabled", () => {
@@ -94,8 +94,8 @@ test("#8497 pull example and environment hints stay topology-safe", () => {
const envExample = read(".env.example");
const envReference = read("docs/reference/ENVIRONMENT.md");
assert.match(quadlet, /Image=docker\.io\/cheaperinference\/omniroute:latest/);
assert.doesNotMatch(quadlet, /(?:diegosouzapw|cheaperinference)\/omniroute:base/);
assert.match(quadlet, /Image=docker\.io\/diegosouzapw\/omniroute:latest/);
assert.doesNotMatch(quadlet, /diegosouzapw\/omniroute:base/);
for (const source of [envExample, envReference]) {
assert.match(source, /any Podman topology/);

View File

@@ -0,0 +1,61 @@
/**
* bootstrapEmbeddedServices must not supervise a service whose API key cannot be
* loaded. The key is the service's own credential (9router API key, Mux auth token,
* Dario admin token, ...): starting the service with a fixed fallback string would hand
* it a credential anyone can guess. The service is skipped instead; the on-demand
* /api/services/<name>/* path then surfaces the key error to the operator.
*/
import { after, before, test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const ORIGINAL_STORAGE_KEY = process.env.STORAGE_ENCRYPTION_KEY;
const ORIGINAL_DATA_DIR = process.env.DATA_DIR;
// Own database directory: another test file may share the inherited DATA_DIR.
const TEST_DATA_DIR = fs.mkdtempSync(
path.join(process.env.DATA_DIR || os.tmpdir(), "bootstrap-service-key-")
);
process.env.DATA_DIR = TEST_DATA_DIR;
// Without a storage key an encrypted column cannot be decrypted, which is the
// degraded state this test needs.
delete process.env.STORAGE_ENCRYPTION_KEY;
const core = await import("../../../src/lib/db/core.ts");
const { upsertVersionManagerTool } = await import("../../../src/lib/db/versionManager.ts");
const { getSupervisor, unregisterSupervisor } =
await import("../../../src/lib/services/registry.ts");
const { bootstrapEmbeddedServices } = await import("../../../src/lib/services/bootstrap.ts");
before(() => {
core.resetDbInstance();
});
after(() => {
unregisterSupervisor("mux");
unregisterSupervisor("9router");
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
if (ORIGINAL_DATA_DIR === undefined) delete process.env.DATA_DIR;
else process.env.DATA_DIR = ORIGINAL_DATA_DIR;
if (ORIGINAL_STORAGE_KEY === undefined) delete process.env.STORAGE_ENCRYPTION_KEY;
else process.env.STORAGE_ENCRYPTION_KEY = ORIGINAL_STORAGE_KEY;
});
test("a service whose stored key cannot be decrypted is not supervised", async () => {
// Installed, not auto-started, with an encrypted key that cannot be read back.
await upsertVersionManagerTool({
tool: "mux",
status: "installed",
autoStart: false,
apiKey: "enc:v1:00:00:00",
});
// A healthy service next to it keeps working.
await upsertVersionManagerTool({ tool: "9router", status: "installed", autoStart: false });
await bootstrapEmbeddedServices();
assert.equal(getSupervisor("mux"), null, "mux must not run with a fallback credential");
assert.notEqual(getSupervisor("9router"), null, "services with a readable key still register");
});

View File

@@ -0,0 +1,329 @@
/**
* The embedded-services WebSocket proxy (initEmbedWsProxy, default :20131) tunnels a
* client into an embedded service and adds that service's own Authorization header to
* the tunnel. It must therefore apply the same decision as the HTTP embed route
* (`/dashboard/providers/services/<name>/embed/`, LOCAL_ONLY + management auth) before
* it opens the tunnel:
*
* - the TCP peer is loopback and no reverse-proxy hop header is present;
* - a browser Origin, when sent, is one of the dashboard origins;
* - the caller holds a dashboard session or a management-scope API key, unless the
* dashboard itself runs without login (then loopback + Origin is the same bar the
* HTTP embed route applies).
*
* A rejected upgrade never reaches the upstream service, so the service credential is
* never sent for an unauthorized caller.
*
* The test drives the real server (initEmbedWsProxy) over TCP against a fake upstream
* that records what it receives.
*/
import { after, before, describe, test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import net from "node:net";
import os from "node:os";
import path from "node:path";
import { createManagementSessionToken } from "../../helpers/managementSession.ts";
const ENV_KEYS = [
"DATA_DIR",
"JWT_SECRET",
"API_KEY_SECRET",
"OMNIROUTE_API_KEY",
"ROUTER_API_KEY",
"INITIAL_PASSWORD",
"EMBED_WS_PROXY_HOST",
"EMBED_WS_PROXY_PORT",
"LIVE_WS_HOST",
"LIVE_WS_ALLOWED_ORIGINS",
"LIVE_WS_ALLOWED_HOSTS",
"PORT",
"DASHBOARD_PORT",
] as const;
const ORIGINAL_ENV = Object.fromEntries(ENV_KEYS.map((k) => [k, process.env[k]]));
function getFreePort(): Promise<number> {
return new Promise((resolve, reject) => {
const srv = net.createServer();
srv.once("error", reject);
srv.listen(0, "127.0.0.1", () => {
const addr = srv.address();
const port = addr && typeof addr === "object" ? addr.port : null;
srv.close(() => (port ? resolve(port) : reject(new Error("no port"))));
});
});
}
const PROXY_PORT = await getFreePort();
// Own database directory: another test file may share the inherited DATA_DIR.
const TEST_DATA_DIR = fs.mkdtempSync(
path.join(process.env.DATA_DIR || os.tmpdir(), "embed-ws-upgrade-auth-")
);
process.env.DATA_DIR = TEST_DATA_DIR;
process.env.JWT_SECRET = "test-jwt-secret-embed-ws-upgrade-auth";
process.env.API_KEY_SECRET = "test-api-key-secret-embed-ws-upgrade-auth";
// The env master key is materialised with `manage` scope — keep it out of the matrix.
delete process.env.OMNIROUTE_API_KEY;
delete process.env.ROUTER_API_KEY;
delete process.env.INITIAL_PASSWORD;
delete process.env.LIVE_WS_HOST;
delete process.env.LIVE_WS_ALLOWED_ORIGINS;
delete process.env.LIVE_WS_ALLOWED_HOSTS;
delete process.env.PORT;
delete process.env.DASHBOARD_PORT;
// Bind every interface so the test can also reach the proxy from a non-loopback
// address of this machine (the documented LIVE_WS_HOST=0.0.0.0 exposure).
process.env.EMBED_WS_PROXY_HOST = "0.0.0.0";
process.env.EMBED_WS_PROXY_PORT = String(PROXY_PORT);
const core = await import("../../../src/lib/db/core.ts");
const apiKeysDb = await import("../../../src/lib/db/apiKeys.ts");
const { updateSettings } = await import("../../../src/lib/db/settings.ts");
const { upsertVersionManagerTool } = await import("../../../src/lib/db/versionManager.ts");
const { getOrCreateApiKey } = await import("../../../src/lib/services/apiKey.ts");
const { registerSupervisor, unregisterSupervisor } =
await import("../../../src/lib/services/registry.ts");
const embedWsProxy = await import("../../../src/lib/services/embedWsProxy.ts");
const DASHBOARD_ORIGIN = "http://127.0.0.1:20128";
const FOREIGN_ORIGIN = "https://attacker.example";
/** First non-internal IPv4 address of this machine, if any. */
function lanAddress(): string | null {
for (const list of Object.values(os.networkInterfaces())) {
for (const iface of list ?? []) {
if (iface.family === "IPv4" && !iface.internal) return iface.address;
}
}
return null;
}
// ── fake upstream service ──────────────────────────────────────────────────
const upstreamRequests: string[] = [];
const upstream = net.createServer((sock) => {
let buf = "";
let answered = false;
sock.on("data", (chunk) => {
buf += chunk.toString("latin1");
if (!answered && buf.includes("\r\n\r\n")) {
answered = true;
upstreamRequests.push(buf);
sock.write(
"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n"
);
}
});
sock.on("error", () => {});
});
/**
* Send a raw WebSocket upgrade for /9router/ws to the proxy and resolve with the
* response status code (0 when the connection closed without a status line).
*/
function attemptUpgrade(host: string, extraHeaders: Record<string, string> = {}): Promise<number> {
return new Promise((resolve, reject) => {
const sock = net.connect(PROXY_PORT, host);
let buf = "";
const timer = setTimeout(() => {
sock.destroy();
reject(new Error("timed out waiting for the upgrade response"));
}, 8000);
const finish = () => {
clearTimeout(timer);
const m = /^HTTP\/1\.1 (\d{3})/.exec(buf);
sock.destroy();
resolve(m ? Number(m[1]) : 0);
};
sock.on("connect", () => {
const lines = [
"GET /9router/ws HTTP/1.1",
`Host: ${host}:${PROXY_PORT}`,
"Connection: Upgrade",
"Upgrade: websocket",
"Sec-WebSocket-Version: 13",
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==",
...Object.entries(extraHeaders).map(([k, v]) => `${k}: ${v}`),
];
sock.write(`${lines.join("\r\n")}\r\n\r\n`);
});
sock.on("data", (chunk) => {
buf += chunk.toString("latin1");
if (buf.includes("\r\n\r\n")) finish();
});
sock.on("close", finish);
sock.on("error", () => {});
});
}
/** Run one upgrade and report the status plus how many requests reached upstream. */
async function probe(host: string, headers: Record<string, string> = {}) {
const before = upstreamRequests.length;
const status = await attemptUpgrade(host, headers);
const forwarded = upstreamRequests.slice(before);
return { status, forwarded };
}
async function waitForProxy(): Promise<void> {
const deadline = Date.now() + 10_000;
while (!globalThis.__omnirouteEmbedWsStarted) {
if (Date.now() > deadline) throw new Error("embed WS proxy did not start");
await new Promise((r) => setTimeout(r, 20));
}
}
let proxyServer: { close: (cb?: () => void) => unknown } | undefined;
let serviceKey = "";
let manageKey = "";
let readKey = "";
let sessionCookie = "";
before(async () => {
core.resetDbInstance();
await new Promise<void>((resolve) => upstream.listen(0, "127.0.0.1", () => resolve()));
const upstreamPort = (upstream.address() as net.AddressInfo).port;
await upsertVersionManagerTool({ tool: "9router", status: "installed", port: upstreamPort });
serviceKey = await getOrCreateApiKey("9router");
registerSupervisor({
getStatus: () => ({
tool: "9router",
state: "running",
port: upstreamPort,
pid: null,
health: "healthy",
startedAt: null,
lastError: null,
}),
} as never);
manageKey = (await apiKeysDb.createApiKey("operator", "machine-embed-ws", ["manage"])).key;
readKey = (await apiKeysDb.createApiKey("inference", "machine-embed-ws", ["read"])).key;
sessionCookie = `auth_token=${await createManagementSessionToken()}`;
globalThis.__omnirouteEmbedWsStarted = undefined;
proxyServer = embedWsProxy.initEmbedWsProxy() as typeof proxyServer;
await waitForProxy();
});
after(async () => {
unregisterSupervisor("9router");
await new Promise<void>((resolve) => upstream.close(() => resolve()));
if (proxyServer) await new Promise<void>((resolve) => proxyServer!.close(() => resolve()));
globalThis.__omnirouteEmbedWsStarted = undefined;
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
for (const k of ENV_KEYS) {
if (ORIGINAL_ENV[k] === undefined) delete process.env[k];
else process.env[k] = ORIGINAL_ENV[k];
}
});
describe("embed WS proxy — login required", () => {
before(async () => {
await updateSettings({ requireLogin: true, password: "hashed-password-for-test" });
});
test("an upgrade without any credential is rejected and never reaches the service", async () => {
const { status, forwarded } = await probe("127.0.0.1", { Origin: DASHBOARD_ORIGIN });
assert.equal(status, 401);
assert.equal(forwarded.length, 0, "the service must not see the upgrade");
});
test("an API key without a management scope is rejected", async () => {
const { status, forwarded } = await probe("127.0.0.1", {
Origin: DASHBOARD_ORIGIN,
Authorization: `Bearer ${readKey}`,
});
assert.equal(status, 403);
assert.equal(forwarded.length, 0);
});
test("a management key opens the tunnel and only the service credential is forwarded", async () => {
const { status, forwarded } = await probe("127.0.0.1", {
Origin: DASHBOARD_ORIGIN,
Authorization: `Bearer ${manageKey}`,
});
assert.equal(status, 101);
assert.equal(forwarded.length, 1);
const sent = forwarded[0];
assert.match(sent, new RegExp(`\\r\\nAuthorization: Bearer ${serviceKey}\\r\\n`));
assert.ok(!sent.includes(manageKey), "the caller's own key must not reach the service");
assert.ok(!/\r\norigin:/i.test(sent), "Origin is not forwarded");
});
test("a dashboard session cookie opens the tunnel and the cookie is not forwarded", async () => {
const { status, forwarded } = await probe("127.0.0.1", {
Origin: DASHBOARD_ORIGIN,
Cookie: sessionCookie,
});
assert.equal(status, 101);
assert.equal(forwarded.length, 1);
assert.ok(!/\r\ncookie:/i.test(forwarded[0]));
});
test("a foreign Origin is rejected even with a valid management key", async () => {
const { status, forwarded } = await probe("127.0.0.1", {
Origin: FOREIGN_ORIGIN,
Authorization: `Bearer ${manageKey}`,
});
assert.equal(status, 403);
assert.equal(forwarded.length, 0);
});
test("a request relayed by a reverse proxy is not treated as local", async () => {
const { status, forwarded } = await probe("127.0.0.1", {
Origin: DASHBOARD_ORIGIN,
Authorization: `Bearer ${manageKey}`,
"X-Forwarded-For": "203.0.113.9",
});
assert.equal(status, 403);
assert.equal(forwarded.length, 0);
});
test("a non-loopback peer is rejected even with a valid management key", async (t) => {
const lan = lanAddress();
if (!lan) {
t.skip("no non-loopback IPv4 interface on this machine");
return;
}
const { status, forwarded } = await probe(lan, {
Origin: DASHBOARD_ORIGIN,
Authorization: `Bearer ${manageKey}`,
});
assert.equal(status, 403);
assert.equal(forwarded.length, 0);
});
});
describe("embed WS proxy — dashboard login disabled", () => {
before(async () => {
await updateSettings({ requireLogin: false });
});
test("a loopback upgrade from the dashboard origin is accepted, as on the HTTP embed route", async () => {
const { status, forwarded } = await probe("127.0.0.1", { Origin: DASHBOARD_ORIGIN });
assert.equal(status, 101);
assert.equal(forwarded.length, 1);
});
test("a foreign Origin is still rejected", async () => {
const { status, forwarded } = await probe("127.0.0.1", { Origin: FOREIGN_ORIGIN });
assert.equal(status, 403);
assert.equal(forwarded.length, 0);
});
test("a non-loopback peer is still rejected", async (t) => {
const lan = lanAddress();
if (!lan) {
t.skip("no non-loopback IPv4 interface on this machine");
return;
}
const { status, forwarded } = await probe(lan, { Origin: DASHBOARD_ORIGIN });
assert.equal(status, 403);
assert.equal(forwarded.length, 0);
});
});

View File

@@ -1,92 +0,0 @@
// @vitest-environment jsdom
/**
* The plugins page must tell the operator that plugins run with the full privileges of the
* OmniRoute process. The manifest's `requires.permissions` is not a sandbox (it only selects
* which environment variables the plugin process receives), so the notice is shown whether
* or not any plugin is installed and cannot be dismissed.
*/
import React from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { NextIntlClientProvider } from "next-intl";
import messages from "../../../src/i18n/messages/en.json";
vi.mock("next/navigation", () => ({
useRouter: () => ({ push: vi.fn() }),
usePathname: () => "/dashboard/plugins",
}));
vi.mock("@/store/notificationStore", () => ({
useNotificationStore: () => ({ addNotification: vi.fn() }),
}));
let pluginList: unknown[] = [];
vi.stubGlobal(
"fetch",
vi
.fn()
.mockImplementation(() =>
Promise.resolve({ ok: true, json: async () => ({ plugins: pluginList }) })
)
);
import PluginsPage from "../../../src/app/(dashboard)/dashboard/plugins/page";
describe("plugins page — full-privileges notice", () => {
let container: HTMLDivElement;
let root: ReturnType<typeof createRoot>;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
});
afterEach(() => {
act(() => {
root.unmount();
});
document.body.removeChild(container);
pluginList = [];
});
async function renderPage() {
await act(async () => {
root.render(
<NextIntlClientProvider locale="en" messages={{ plugins: messages.plugins }}>
<PluginsPage />
</NextIntlClientProvider>
);
});
}
function notice(): HTMLElement | null {
return container.querySelector('[data-slot="alert"][data-variant="warning"]');
}
it("shows the notice when no plugin is installed", async () => {
await renderPage();
const alert = notice();
expect(alert).not.toBeNull();
expect(alert!.textContent).toContain(messages.plugins.privilegesWarningTitle);
expect(alert!.textContent).toContain(messages.plugins.privilegesWarningBody);
expect(alert!.querySelector("button.ci-alert__dismiss")).toBeNull();
});
it("shows the notice alongside installed plugins", async () => {
pluginList = [
{ name: "demo", version: "1.0.0", status: "active", enabled: true, hooks: ["onRequest"] },
];
await renderPage();
expect(container.textContent).toContain("demo");
expect(notice()?.textContent).toContain(messages.plugins.privilegesWarningTitle);
});
it("the notice says permissions are not a sandbox and to trust the plugin", () => {
const body = messages.plugins.privilegesWarningBody;
expect(body).toMatch(/whatever permissions its manifest declares/);
expect(body).toMatch(/only plugins you trust/);
});
});