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
A sign-in goes on only to a path on this site (#433)
github-actions[bot]7db36fd28c13
diff --git a/ui/src/app/login/page.tsx b/ui/src/app/login/page.tsxindex 76ebfa16..6cfbbe42 100644--- a/ui/src/app/login/page.tsx+++ b/ui/src/app/login/page.tsx@@ -5,6 +5,7 @@ import { GoogleButton, GOOGLE_ENABLED } from '@/components/GoogleButton';import { stashInvite, takePendingInvite } from '@/app/(app)/billing/lib';import { SELF_HOSTED } from '@/lib/edition';import { SelfHostLogin } from '@/components/SelfHostLogin';+import { safeNext } from '@/lib/safe-next';// HarnessRouter is a subscribable product over AgentStudio orgs. The sign-in org picker lists ONLY// orgs that subscribed to HR (hr_subscribed flag). The account itself is the shared AgentStudio user.@@ -17,7 +18,7 @@ export default function LoginPage() {// and offers Google — all of which need services a single box doesn't have.if (SELF_HOSTED) {const next = typeof window !== 'undefined'- ? new URLSearchParams(window.location.search).get('next') || ''+ ? safeNext(new URLSearchParams(window.location.search).get('next')): '';return <SelfHostLogin next={next} />;}diff --git a/ui/src/components/SelfHostLogin.tsx b/ui/src/components/SelfHostLogin.tsxindex 9741ebc4..3acb422b 100644--- a/ui/src/components/SelfHostLogin.tsx+++ b/ui/src/components/SelfHostLogin.tsx@@ -5,6 +5,7 @@// resets passwords by email and offers Google — every one of those needs a service this box does// not have. Reusing it would mean disabling four flows and explaining the remnants.import { useState } from 'react';+import { safeNext } from '@/lib/safe-next';export function SelfHostLogin({ next }: { next: string }) {const [username, setUsername] = useState('');@@ -27,7 +28,8 @@ export function SelfHostLogin({ next }: { next: string }) {}// A full navigation, not a client route change: the middleware has to see the new cookie,// and every page under it was rendered as unauthenticated.- window.location.assign(next || '/harnesses');+ // Only a path on this site: `next` is whatever the link said (GHSA-59mq-hx4p-fw48).+ window.location.assign(safeNext(next));} catch {setErr('Could not reach this instance.');} finally {diff --git a/ui/src/lib/safe-next.test.ts b/ui/src/lib/safe-next.test.tsnew file mode 100644index 00000000..2a70d4ea--- /dev/null+++ b/ui/src/lib/safe-next.test.ts@@ -0,0 +1,48 @@+import { safeNext } from './safe-next';++// GHSA-59mq-hx4p-fw48: a sign-in link must not be able to send the person to another site.+test.each([+ ['https://evil.example/'],+ ['http://evil.example'],+ ['javascript:alert(1)'],+ ['data:text/html,hi'],+ ['evil.example'],+ ['//evil.example'],+ ['//evil.example/harnesses'],+ ['/\\evil.example'],+ ['\\\\evil.example'],+ ['/\\/evil.example'],+ ['/%2F%2Fevil.example'],+ ['/%2fevil.example'],+ ['/%5Cevil.example'],+ ['/%5cevil.example'],+ ['/\t/evil.example'],+ ['/\n/evil.example'],+ ['/\r//evil.example'],+ [' /harnesses'],+ [''],+])('%j is refused for the default', (raw) => {+ expect(safeNext(raw)).toBe('/harnesses');+});++test.each([+ ['/harnesses', '/harnesses'],+ ['/kits?tab=sheets', '/kits?tab=sheets'],+ ['/harnesses/chrn_abc#settings', '/harnesses/chrn_abc#settings'],+ ['/plugins?q=a%20b', '/plugins?q=a%20b'],+])('%j, a path on this site, is kept', (raw, want) => {+ expect(safeNext(raw)).toBe(want);+});++test('what the middleware writes survives the round trip', () => {+ const pathname = '/harnesses/chrn_abc';+ const search = '?view=tasks';+ const link = `/login?next=${encodeURIComponent(pathname + search)}`;+ const next = new URLSearchParams(link.split('?')[1]).get('next');+ expect(safeNext(next)).toBe(pathname + search);+});++test('nothing at all, and a custom default', () => {+ expect(safeNext(null)).toBe('/harnesses');+ expect(safeNext(undefined, '/quickstart')).toBe('/quickstart');+});diff --git a/ui/src/lib/safe-next.ts b/ui/src/lib/safe-next.tsnew file mode 100644index 00000000..f1d1bddb--- /dev/null+++ b/ui/src/lib/safe-next.ts@@ -0,0 +1,29 @@+// Where a sign-in may send the browser next: a path on this site, or the default.+//+// The value comes from the address bar (`/login?next=...`), so anyone can write it into a link and+// hand it to someone about to sign in. Sent to another site, that person lands there straight after+// typing their password on ours (reported privately, GHSA-59mq-hx4p-fw48). Only a path that starts+// with a single "/" passes, and the URL parser has the last word. Refused, each one a way a browser+// would leave the site:+// https://evil.example, javascript:... absolute or scheme-bearing+// //evil.example scheme-relative+// /\evil.example, \\evil.example a backslash, which browsers read as "/"+// /%2F%2Fevil.example, /%5Cevil.example an encoded slash or backslash+// /<tab>/evil.example a tab or line break, which browsers drop before parsing+// The middleware only ever writes a plain path here, so nothing it sends is refused.+const SITE = 'https://site.invalid';++export function safeNext(raw: string | null | undefined, fallback = '/harnesses'): string {+ const v = String(raw ?? '');+ if (!v.startsWith('/') || v.startsWith('//')) return fallback;+ if (/[\\\u0000-\u001f\u007f]/.test(v)) return fallback;+ if (/%(2f|5c)/i.test(v)) return fallback;+ let u: URL;+ try {+ u = new URL(v, SITE);+ } catch {+ return fallback;+ }+ if (u.origin !== SITE) return fallback;+ return u.pathname + u.search + u.hash;+}