Skip to content

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.

The gateway trusts self-asserted identity only when its operator chose that (#426)

github-actions[bot]48a26cdf9c45
diff --git a/docs/self-hosting-guide.md b/docs/self-hosting-guide.md
index c12399f3..70de6cfb 100644
--- a/docs/self-hosting-guide.md
+++ b/docs/self-hosting-guide.md
@@ -953,6 +953,8 @@ docker build -t harnessrouter --build-arg WITH_BROWSER=1 .
| `HARNESS_RESP_HOLD_S` | `3` | How long the gateway lets the runner hold a request for a turn's events. `0` asks every 1.2 s as before 0.30.1. |
| `HARNESS_INTERNAL_KEY` | generated | Per-container; never leaves the process tree. |
+Outside this image the gateway's own default for `HR_IDENTITY_MODE` is `enforce`: a request that carries the internal key beside a sign-in token is answered as the organization and member the token proves, and refused when the token does not verify. Set `off` only where, as here, the console in front of the gateway pins the one organization itself.
+
</details>
## Using the API
diff --git a/gateway/app.py b/gateway/app.py
index fe2b44e3..54817164 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -299,7 +299,14 @@ INTERNAL_KEY = os.environ.get("HARNESS_INTERNAL_KEY", "")
# service-to-service (the engine executor) and keep header trust — key possession is the service
# credential. Modes: observe (count/log, keep header trust) -> enforce (claims are authoritative;
# key + a present-but-invalid Authorization is REJECTED).
-HR_IDENTITY_MODE = os.environ.get("HR_IDENTITY_MODE", "observe")
+#
+# Unset, or anything but "off" or "observe", means enforce. A console that is not in self-hosted mode
+# attaches the internal key to every request that carries an Authorization header, so a gateway that
+# trusted the identity headers by default let a junk bearer assert any organization and member
+# (reported privately, GHSA-qrr8-m92f-7vfp). The self-hosted entrypoint sets "off" on purpose: its
+# console pins the one organization and gives the key only to a signed-in session. "observe" is a
+# migration step a multi-tenant operator chooses, never a default.
+HR_IDENTITY_MODE = {"off": "off", "observe": "observe"}.get(os.environ.get("HR_IDENTITY_MODE", "").strip().lower(), "enforce")
AUTH_JWT_SECRET = os.environ.get("AUTH_JWT_SECRET", "")
# Deploy fingerprint (baked at image build via the GIT_SHA build-arg, see Dockerfile) — lets
# release verification bind this running instance to the exact source commit it was built from.
diff --git a/gateway/tests/test_identity_default.py b/gateway/tests/test_identity_default.py
new file mode 100644
index 00000000..425871c7
--- /dev/null
+++ b/gateway/tests/test_identity_default.py
@@ -0,0 +1,67 @@
+"""A gateway trusts self-asserted identity headers only when its operator chose that (GHSA-qrr8-m92f-7vfp).
+
+A console that is not in self-hosted mode attaches the internal key to every request carrying an
+Authorization header. With the identity mode unset the gateway used to run "observe", which keeps
+the X-Harness-Org / X-Harness-Member headers beside a bearer that does not verify, so a junk bearer
+could assert any organization. Unset now means enforce; the self-hosted entrypoint sets "off".
+"""
+import os
+import pathlib
+import subprocess
+import sys
+
+import pytest
+from fastapi.testclient import TestClient
+
+sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
+import app as gw # noqa: E402
+
+KEY = os.environ["HARNESS_INTERNAL_KEY"]
+GATEWAY = pathlib.Path(__file__).resolve().parents[1]
+
+
+def _mode_with(value) -> str:
+ env = {k: v for k, v in os.environ.items() if k != "HR_IDENTITY_MODE"}
+ if value is not None:
+ env["HR_IDENTITY_MODE"] = value
+ out = subprocess.run([sys.executable, "-c", "import app; print('MODE=' + app.HR_IDENTITY_MODE)"],
+ cwd=GATEWAY, env=env, capture_output=True, text=True, timeout=180)
+ line = [x for x in out.stdout.splitlines() if x.startswith("MODE=")]
+ assert line, out.stderr[-600:]
+ return line[-1][5:]
+
+
+def test_unset_or_unknown_means_enforce_and_the_two_named_modes_are_kept():
+ assert _mode_with(None) == "enforce"
+ assert _mode_with("") == "enforce"
+ assert _mode_with("Enforce ") == "enforce"
+ assert _mode_with("strict") == "enforce" # a typo fails closed, not open
+ assert _mode_with(" OFF") == "off"
+ assert _mode_with("observe") == "observe"
+
+
+def test_self_hosted_entrypoint_still_sets_off():
+ entry = (GATEWAY.parent / "docker" / "entrypoint.sh").read_text()
+ assert 'export HR_IDENTITY_MODE="${HR_IDENTITY_MODE:-off}"' in entry
+
+
+def client():
+ with TestClient(gw.app) as c:
+ yield c
+
+
+def test_under_enforce_a_junk_bearer_cannot_assert_an_organization(client, monkeypatch):
+ monkeypatch.setattr(gw, "HR_IDENTITY_MODE", "enforce")
+ asserted = {"x-harness-internal": KEY, "x-harness-org": "org.someone-else", "x-harness-member": "[email protected]"}
+ for junk in ("Bearer junk", "Bearer a.b.c", "Bearer sk-hr-not-a-real-key"):
+ r = client.get("/v1/orgs/org.someone-else/harnesses", headers={**asserted, "authorization": junk})
+ assert r.status_code == 401, (junk, r.status_code, r.text[:200])
+ # a service holding the key and sending no Authorization keeps header identity, as before
+ assert client.get("/v1/orgs/org.someone-else/harnesses", headers=asserted).status_code == 200
+
+
+def test_observe_remains_an_explicit_choice_with_its_documented_behaviour(client, monkeypatch):
+ monkeypatch.setattr(gw, "HR_IDENTITY_MODE", "observe")
+ h = {"x-harness-internal": KEY, "x-harness-org": "org.a", "x-harness-member": "[email protected]", "authorization": "Bearer junk"}
+ assert client.get("/v1/orgs/org.a/harnesses", headers=h).status_code == 200