HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
fix(selfhost): a bearer request is judged by its key, and discovery needs no key at all
richard-epsillae97dfbac2d7f
diff --git a/ui/src/app/api/harness/[...path]/route.ts b/ui/src/app/api/harness/[...path]/route.tsindex bd78a109..ba5429f0 100644--- a/ui/src/app/api/harness/[...path]/route.ts+++ b/ui/src/app/api/harness/[...path]/route.ts@@ -17,6 +17,7 @@// constants — a request from the browser cannot claim an identity this box doesn't have.import type { NextRequest } from 'next/server';import { LOCAL_MEMBER, LOCAL_ORG, SELF_HOSTED } from '@/lib/edition';+import { AUTH_DISABLED, SESSION_COOKIE, sessionValid } from '@/lib/selfhost-auth';export const dynamic = 'force-dynamic';export const maxDuration = 800; // long agent turns stream for minutes@@ -40,11 +41,23 @@ async function proxy(req: NextRequest, ctx: { params: Promise<{ path: string[] }// claims, the forwarded org/member headers are no longer trusted for identity. A request with// no bearer (no session) gets no key -> the gateway 401s it, so it can't ride the BFF onto the// internal path with self-asserted identity.- if (INTERNAL_KEY && (auth || SELF_HOSTED)) headers['x-harness-internal'] = INTERNAL_KEY;- if (SELF_HOSTED) {+ //+ // SELF-HOSTED: trust is the SESSION, not the transport. This used to stamp the internal key on+ // every request because "there is no login" — written before the login gate existed. Once the+ // gate let bearer-carrying API calls through to here (so console-minted sk-hr keys work at+ // all), unconditional stamping would have authenticated ANY bearer as the local org. So: a+ // caller with a valid session cookie (the signed-in console) gets internal trust and the+ // pinned local identity; anyone else forwards their Authorization bare, and the gateway's+ // _apikey_resolve is the judge — an invalid key gets the gateway's own 401.+ const selfhostTrusted = SELF_HOSTED+ && (AUTH_DISABLED || await sessionValid(req.cookies.get(SESSION_COOKIE)?.value));+ if (INTERNAL_KEY && (SELF_HOSTED ? selfhostTrusted : auth)) {+ headers['x-harness-internal'] = INTERNAL_KEY;+ }+ if (selfhostTrusted) {headers['x-harness-org'] = LOCAL_ORG;headers['x-harness-member'] = LOCAL_MEMBER;- } else {+ } else if (!SELF_HOSTED) {const org = req.headers.get('x-harness-org');if (org) headers['x-harness-org'] = org;const member = req.headers.get('x-harness-member');diff --git a/ui/src/middleware.ts b/ui/src/middleware.tsindex 9498286d..d7883d53 100644--- a/ui/src/middleware.ts+++ b/ui/src/middleware.ts@@ -32,8 +32,11 @@ const STATIC_ASSET = /\.(svg|png|jpe?g|gif|webp|avif|ico|woff2?|ttf|otf|css|js|m* own format: pages and everything else stay cookie-gated. */function isApiKeyCall(req: NextRequest, path: string): boolean {if (!path.startsWith('/api/harness/')) return false;- const auth = req.headers.get('authorization') || '';- return /^Bearer sk-hr-[A-Za-z0-9]+$/.test(auth);+ // ANY bearer, not just well-formed keys: an invalid credential must get the gateway's own+ // 401 (error.type authentication_error, UHP-Version header) — the shape UHP check A-02+ // requires — not this gate's sign-in JSON. The proxy attaches internal trust only for+ // cookie-authenticated callers, so a bearer-only request stands or falls on its key alone.+ return (req.headers.get('authorization') || '').toLowerCase().startsWith('bearer ');}/** Reachable without a session: the login page, the endpoints it posts to, and static assets.@@ -42,6 +45,10 @@ function isPublic(path: string): boolean {return path === '/login'|| path === '/api/selfhost/login'|| path === '/api/selfhost/logout'+ // UHP discovery is unauthenticated BY SPEC (D-02): a client must be able to learn whether+ // this is a UHP server before deciding what credential to present. The document is version+ // metadata — no user data.+ || path === '/api/harness/v1/uhp'|| path.startsWith('/_next/')// An /api path is never a static asset, whatever it ends with. Neither is /data — those are// files a TASK produced, and agents write .png, .svg, .css and .js routinely. Matching those