Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(board): bind federation signatures to their endpoint

rubenluetke10-beepbe3ddc9e1b60
diff --git a/board-backend/README.md b/board-backend/README.md
index 032c9bf6c4..d248b8d8a3 100644
--- a/board-backend/README.md
+++ b/board-backend/README.md
@@ -243,6 +243,7 @@ The schema is additive (`create_all`), data is preserved.
| Brute force against the admin token | Constant-time comparison + rate limit (10/min/IP). |
| Replay of old pushes | `payload.ts_ms` must lie within +/- 5 min. |
| Tampering after signing | Re-canonicalize + Ed25519 verify on the server. |
+| Replaying a signed body at another endpoint | The signed `aud` field must equal `"<METHOD> <path>"` of the receiving route (`board_backend.crypto.signed_audience`); a reaction names the friend's inbound route. Clients and backend must both be on this version. |
| PII leak on a bug in the local filter | Pydantic `extra='forbid'` on every schema layer. |
| Compromised container | Non-root user (uid 1000), only `/data` writable. |
diff --git a/board-backend/board_backend/auth.py b/board-backend/board_backend/auth.py
index 0c5534c290..c2a0f491b7 100644
--- a/board-backend/board_backend/auth.py
+++ b/board-backend/board_backend/auth.py
@@ -9,7 +9,8 @@ Three gates:
3. PII filter: implicit via the Pydantic schema ``extra='forbid'`` (Plan §C-Sec).
The signature-verify order is:
-``schema-validate → pubkey-registered? → signature-valid? → ts within window?``
+``schema-validate → pubkey-registered? → signature-valid? → aud == this
+endpoint? → ts within window?``
Schema and pubkey lookup are cheap; the crypto only runs after that.
"""
@@ -24,7 +25,7 @@ from fastapi import Depends, Header, HTTPException, Request, status
from sqlalchemy.orm import Session
from .config import Settings
-from .crypto import verify_with_recanonicalize
+from .crypto import AUDIENCE_FIELD, signed_audience, verify_with_recanonicalize
from .db import session_dep
from .models import Identity
from .rate_limit import RateLimiter
@@ -83,6 +84,32 @@ def require_admin_token(
# Signed-request gate
# ----------------------------------------------------------------------
+def _request_path(request: Request) -> str:
+ """The route path as the client addressed it, minus a deployment prefix."""
+ path = request.url.path
+ root = str(request.scope.get("root_path") or "")
+ if root and path.startswith(root):
+ path = path[len(root):] or "/"
+ return path
+
+
+def _check_audience(request: Request, payload: dict) -> dict:
+ """Require the signed ``aud`` to name THIS endpoint; return the payload
+ without it so route schemas (``extra='forbid'``) see only their fields.
+
+ Runs after the signature check, so ``aud`` is authenticated: a body signed
+ for one route cannot be replayed at another (reactions are forwarded to
+ friends verbatim, which made the owner's signed bodies available to them).
+ """
+ expected = signed_audience(request.method, _request_path(request))
+ if payload.get(AUDIENCE_FIELD) != expected:
+ raise HTTPException(
+ status_code=401,
+ detail=f"signature audience does not match {expected}",
+ )
+ return {key: value for key, value in payload.items() if key != AUDIENCE_FIELD}
+
+
class SignedAuth:
"""Container that signed routes receive via ``Depends``.
@@ -134,7 +161,10 @@ async def require_signed_request(
):
raise HTTPException(status_code=401, detail="invalid signature")
- # 3. Replay protection
+ # 3. Endpoint binding (authenticated by the signature above)
+ payload = _check_audience(request, payload)
+
+ # 4. Replay protection
ts_ms = payload.get("ts_ms")
if not isinstance(ts_ms, int):
raise HTTPException(status_code=400, detail="payload.ts_ms missing")
@@ -234,6 +264,8 @@ async def require_federation_signed(
):
raise HTTPException(status_code=401, detail="invalid signature")
+ payload = _check_audience(request, payload)
+
ts_ms = payload.get("ts_ms")
if not isinstance(ts_ms, int):
raise HTTPException(status_code=400, detail="payload.ts_ms missing")
diff --git a/board-backend/board_backend/crypto.py b/board-backend/board_backend/crypto.py
index e5c60d1f67..c1229f038a 100644
--- a/board-backend/board_backend/crypto.py
+++ b/board-backend/board_backend/crypto.py
@@ -32,6 +32,30 @@ def canonical_json(payload: Any) -> bytes:
ensure_ascii=False).encode("utf-8")
+#: Payload field that binds a signature to ONE endpoint: ``"<METHOD> <path>"``.
+#: The signature covers only the body, so without it a signed body is valid
+#: on every route whose schema accepts it — and the owner's reactions are
+#: forwarded to friends verbatim, so a friend could replay one at the owner's
+#: own backend (``GET /api/v1/activities``) and read the private feed.
+AUDIENCE_FIELD = "aud"
+
+# A reaction is signed once by the owner's client, sent to the owner's
+# backend, and delivered unchanged to the friend's inbound route. Its audience
+# names that final hop, so both backends accept it and nothing else does.
+_AUDIENCE_ALIASES = {
+ "POST /api/v1/reactions": "POST /api/v1/federation/reactions/inbound",
+}
+
+
+def signed_audience(method: str, path: str) -> str:
+ """The ``aud`` value a signed request to ``method path`` must carry.
+
+ ``path`` is the route path without query string or deployment prefix.
+ """
+ key = f"{method.upper()} {path}"
+ return _AUDIENCE_ALIASES.get(key, key)
+
+
def generate_keypair() -> tuple[str, str]:
"""Generates a new Ed25519 keypair.
diff --git a/board-backend/tests/test_activity.py b/board-backend/tests/test_activity.py
index 4c625b7624..b077612915 100644
--- a/board-backend/tests/test_activity.py
+++ b/board-backend/tests/test_activity.py
@@ -17,7 +17,7 @@ from pathlib import Path
import pytest
from fastapi.testclient import TestClient
-from board_backend.crypto import canonical_json, generate_keypair, sign
+from board_backend.crypto import canonical_json, generate_keypair, sign, signed_audience
from board_backend.models import ActivityItem, Friend
from board_backend.routes.activity import interesting_score
@@ -31,6 +31,7 @@ def _now_ms() -> int:
def _signed_post(client: TestClient, path: str, *, priv: str, pub: str, payload: dict):
+ payload = {"aud": signed_audience("POST", path), **payload}
body = canonical_json(payload)
sig = sign(payload, privkey_hex=priv)
return client.post(
@@ -42,6 +43,7 @@ def _signed_post(client: TestClient, path: str, *, priv: str, pub: str, payload:
def _signed_get(client: TestClient, path: str, *, priv: str, pub: str, params: dict | None = None,
payload: dict | None = None):
payload = payload or {"ts_ms": _now_ms()}
+ payload = {"aud": signed_audience("GET", path), **payload}
body = canonical_json(payload)
sig = sign(payload, privkey_hex=priv)
return client.request(
diff --git a/board-backend/tests/test_pair.py b/board-backend/tests/test_pair.py
index 156ae0a5ce..c1dd36773a 100644
--- a/board-backend/tests/test_pair.py
+++ b/board-backend/tests/test_pair.py
@@ -9,7 +9,7 @@ import pytest
from fastapi.testclient import TestClient
from board_backend.config import Settings
-from board_backend.crypto import canonical_json, generate_keypair, sign
+from board_backend.crypto import canonical_json, generate_keypair, sign, signed_audience
from board_backend.main import create_app
from board_backend.models import Friend, PairToken
@@ -29,6 +29,7 @@ def _register_owner(client: TestClient, pubkey: str, name: str = "Owner") -> Non
def _signed_get(client: TestClient, path: str, *, priv: str, pub: str) -> "TestClient.Response":
payload = {"ts_ms": int(time.time() * 1000)}
+ payload = {"aud": signed_audience("GET", path), **payload}
body = canonical_json(payload)
sig = sign(payload, privkey_hex=priv)
return client.request(
diff --git a/board-backend/tests/test_phase_d_gaps.py b/board-backend/tests/test_phase_d_gaps.py
index aa429c198c..7fcde4da33 100644
--- a/board-backend/tests/test_phase_d_gaps.py
+++ b/board-backend/tests/test_phase_d_gaps.py
@@ -7,7 +7,7 @@ from datetime import datetime, timedelta, timezone
import pytest
from fastapi.testclient import TestClient
-from board_backend.crypto import canonical_json, generate_keypair, sign
+from board_backend.crypto import canonical_json, generate_keypair, sign, signed_audience
from board_backend.models import ActivityItem, Friend
@@ -17,6 +17,7 @@ def _now_ms() -> int:
def _signed(method: str, client: TestClient, path: str, *, priv: str, pub: str,
payload: dict, params: dict | None = None):
+ payload = {"aud": signed_audience(method, path), **payload}
body = canonical_json(payload)
sig = sign(payload, privkey_hex=priv)
return client.request(
diff --git a/board-backend/tests/test_reactions_forget.py b/board-backend/tests/test_reactions_forget.py
index fcd3a3f936..9caac08aa1 100644
--- a/board-backend/tests/test_reactions_forget.py
+++ b/board-backend/tests/test_reactions_forget.py
@@ -10,7 +10,7 @@ import pytest
from fastapi.testclient import TestClient
from board_backend.background import StoriesCleanup
-from board_backend.crypto import canonical_json, generate_keypair, sign
+from board_backend.crypto import canonical_json, generate_keypair, sign, signed_audience
from board_backend.models import ActivityItem, Friend, Reaction
@@ -19,6 +19,7 @@ def _now_ms() -> int:
def _signed_post(client: TestClient, path: str, *, priv: str, pub: str, payload: dict):
+ payload = {"aud": signed_audience("POST", path), **payload}
body = canonical_json(payload)
sig = sign(payload, privkey_hex=priv)
return client.post(
@@ -102,6 +103,78 @@ async def test_reaction_propagates_to_author_backend(client: TestClient) -> None
client.app.state.federation_http = None
+async def test_friend_cannot_replay_a_forwarded_reaction_at_the_owner(
+ client: TestClient,
+) -> None:
+ """The owner's backend forwards the owner-signed reaction body verbatim to
+ the friend. Before signatures named their endpoint, the friend could send
+ that body + signature back to the owner's backend within the replay
+ window and read the private feed (GET /activities) or the friends list.
+ """
+ owner_priv, owner_pub = generate_keypair()
+ _setup_owner(client, owner_pub)
+ _, friend_pub = generate_keypair()
+ factory = client.app.state.session_factory
+ with factory() as session:
+ session.add(Friend(
+ owner_pubkey=owner_pub, friend_pubkey=friend_pub,
+ friend_url="http://friend-backend:8765",
+ friend_display_name="Bob",
+ paired_at=datetime.now(timezone.utc),
+ ))
+ session.commit()
+
+ captured: dict = {}
+
+ async def _handler(req: httpx.Request) -> httpx.Response:
+ captured["sig"] = req.headers.get("x-jarvis-sig")
+ captured["body"] = req.content
+ return httpx.Response(200, json={"accepted": True})
+
+ client.app.state.federation_http = httpx.AsyncClient(
+ transport=httpx.MockTransport(_handler), base_url="http://x", timeout=5.0,
+ )
+ try:
+ resp = _signed_post(client, "/api/v1/reactions", priv=owner_priv, pub=owner_pub,
+ payload={"ts_ms": _now_ms(), "item_id": "fakeitem123",
+ "reaction": "rocket", "author_pubkey": friend_pub})
+ assert resp.status_code == 200, resp.text
+ finally:
+ await client.app.state.federation_http.aclose()
+ client.app.state.federation_http = None
+
+ replay_headers = {"X-Pubkey": owner_pub, "X-Jarvis-Sig": captured["sig"],
+ "Content-Type": "application/json"}
+ for method, path in (("GET", "/api/v1/activities"), ("GET", "/api/v1/friends"),
+ ("GET", "/api/v1/me")):
+ replay = client.request(method, path, content=captured["body"], headers=replay_headers)
+ assert replay.status_code == 401, (path, replay.text)
+
+
+def test_signature_for_one_endpoint_is_refused_at_another(client: TestClient) -> None:
+ owner_priv, owner_pub = generate_keypair()
+ _setup_owner(client, owner_pub)
+ payload = {"ts_ms": _now_ms(), "aud": signed_audience("GET", "/api/v1/me")}
+ body = canonical_json(payload)
+ headers = {"X-Pubkey": owner_pub, "X-Jarvis-Sig": sign(payload, privkey_hex=owner_priv),
+ "Content-Type": "application/json"}
+ assert client.request("GET", "/api/v1/me", content=body, headers=headers).status_code == 200
+ assert client.request("GET", "/api/v1/friends", content=body,
+ headers=headers).status_code == 401
+
+
+def test_signature_without_audience_is_refused(client: TestClient) -> None:
+ owner_priv, owner_pub = generate_keypair()
+ _setup_owner(client, owner_pub)
+ payload = {"ts_ms": _now_ms()}
+ resp = client.request(
+ "GET", "/api/v1/me", content=canonical_json(payload),
+ headers={"X-Pubkey": owner_pub, "X-Jarvis-Sig": sign(payload, privkey_hex=owner_priv),
+ "Content-Type": "application/json"},
+ )
+ assert resp.status_code == 401
+
+
def test_inbound_reaction_persists_when_friend(client: TestClient) -> None:
"""Friend (B) signs an inbound reaction → owner's backend stores it."""
owner_priv, owner_pub = generate_keypair()
@@ -215,7 +288,10 @@ def test_right_to_be_forgotten_removes_all_traces(client: TestClient) -> None:
session.commit()
# B signed DELETE.
- payload = {"ts_ms": _now_ms()}
+ payload = {
+ "ts_ms": _now_ms(),
+ "aud": signed_audience("DELETE", f"/api/v1/federation/identity/{friend_pub}"),
+ }
body = canonical_json(payload)
sig = sign(payload, privkey_hex=friend_priv)
resp = client.request(
@@ -245,7 +321,10 @@ def test_forget_me_path_and_signature_must_match(client: TestClient) -> None:
other_priv, other_pub = generate_keypair()
_setup_owner(client, owner_pub)
- payload = {"ts_ms": _now_ms()}
+ payload = {
+ "ts_ms": _now_ms(),
+ "aud": signed_audience("DELETE", f"/api/v1/federation/identity/{friend_pub}"),
+ }
body = canonical_json(payload)
sig = sign(payload, privkey_hex=other_priv)
diff --git a/board-backend/tests/test_routes.py b/board-backend/tests/test_routes.py
index add3c2f8f8..5288260205 100644
--- a/board-backend/tests/test_routes.py
+++ b/board-backend/tests/test_routes.py
@@ -7,7 +7,7 @@ import time
import pytest
from fastapi.testclient import TestClient
-from board_backend.crypto import canonical_json, generate_keypair, sign
+from board_backend.crypto import canonical_json, generate_keypair, sign, signed_audience
# ----------------------------------------------------------------------
@@ -26,6 +26,7 @@ def _register(client: TestClient, *, pubkey: str, name: str = "Tester",
def _signed_post(client: TestClient, path: str, *, priv: str, pub: str,
payload: dict) -> "TestClient.Response":
+ payload = {"aud": signed_audience("POST", path), **payload}
body = canonical_json(payload)
sig = sign(payload, privkey_hex=priv)
return client.post(
@@ -41,6 +42,7 @@ def _signed_post(client: TestClient, path: str, *, priv: str, pub: str,
def _signed_get(client: TestClient, path: str, *, priv: str, pub: str,
payload: dict) -> "TestClient.Response":
+ payload = {"aud": signed_audience("GET", path), **payload}
body = canonical_json(payload)
sig = sign(payload, privkey_hex=priv)
return client.request(
@@ -158,6 +160,7 @@ def test_signed_sync_rejects_tampered_payload(client: TestClient) -> None:
"voice_commands_count": 0,
"hours_saved_estimate": 0,
}]
+ payload["aud"] = signed_audience("POST", "/api/v1/sync")
sig = sign(payload, privkey_hex=priv)
# Manipulate after signing — a typical replay-tamper vector.
@@ -327,6 +330,7 @@ def test_signature_replay_with_changed_body_rejected(client: TestClient) -> None
priv, pub = generate_keypair()
_register(client, pubkey=pub)
payload = _minimal_payload()
+ payload["aud"] = signed_audience("POST", "/api/v1/sync")
sig = sign(payload, privkey_hex=priv)
# Replay: overwrite ts_ms → signature no longer matches
diff --git a/jarvis/board/sync.py b/jarvis/board/sync.py
index 008ddc9c25..b1872c9c8a 100644
--- a/jarvis/board/sync.py
+++ b/jarvis/board/sync.py
@@ -328,11 +328,12 @@ class SyncClient:
return payload
async def _push(self) -> bool:
- from board_backend.crypto import canonical_json, sign
+ from board_backend.crypto import AUDIENCE_FIELD, canonical_json, sign, signed_audience
assert self._http is not None
assert self._privkey_hex is not None and self._pubkey_hex is not None
payload = self._build_payload()
+ payload[AUDIENCE_FIELD] = signed_audience("POST", "/api/v1/sync")
body = canonical_json(payload)
sig = sign(payload, privkey_hex=self._privkey_hex)
try:
diff --git a/jarvis/ui/web/federation_proxy_routes.py b/jarvis/ui/web/federation_proxy_routes.py
index ad237c6e98..c86715c6bf 100644
--- a/jarvis/ui/web/federation_proxy_routes.py
+++ b/jarvis/ui/web/federation_proxy_routes.py
@@ -27,21 +27,28 @@ from jarvis.board.sync import (
)
try:
- from board_backend.crypto import canonical_json, sign
-except ModuleNotFoundError:
+ from board_backend.crypto import AUDIENCE_FIELD, canonical_json, sign, signed_audience
+except ImportError:
# `board_backend` is a SEPARATE, optional package (the Board-federation
# backend). The base app MUST import this module without it (cloud-first:
# a fresh `pip install .` has no board_backend), so the whole server still
# boots. The federation routes then return a clear 503 when actually called,
- # instead of crashing the server at import time.
+ # instead of crashing the server at import time. ImportError, not only
+ # ModuleNotFoundError: an older installed package without endpoint-bound
+ # signatures (``signed_audience``) must degrade the same way.
def _federation_unavailable(*_a: Any, **_k: Any) -> Any: # type: ignore[misc]
raise HTTPException(
status_code=503,
- detail="Board federation is unavailable — the optional 'board_backend' package is not installed.",
+ detail=(
+ "Board federation is unavailable — the optional 'board_backend' "
+ "package is not installed or is too old."
+ ),
)
+ AUDIENCE_FIELD = "aud"
canonical_json = _federation_unavailable # type: ignore[assignment]
sign = _federation_unavailable # type: ignore[assignment]
+ signed_audience = _federation_unavailable # type: ignore[assignment]
log = logging.getLogger(__name__)
router = APIRouter(prefix="/api/board/federation", tags=["board-federation"])
@@ -216,7 +223,7 @@ async def proxy_get(request: Request,
backend = _backend_url(request)
kr = _KeyringBackend()
privkey, pubkey = _load_or_create_privkey(kr)
- payload = {"ts_ms": int(time.time() * 1000)}
+ payload = {"ts_ms": int(time.time() * 1000), AUDIENCE_FIELD: signed_audience("GET", path)}
body = canonical_json(payload)
headers = _signed_headers(privkey, pubkey, payload)
async with httpx.AsyncClient(timeout=10.0) as c:
@@ -241,7 +248,13 @@ async def proxy_post(request: Request, payload: ProxyPostRequest) -> Any:
backend = _backend_url(request)
kr = _KeyringBackend()
privkey, pubkey = _load_or_create_privkey(kr)
- full_body = {**payload.body, "ts_ms": int(time.time() * 1000)}
+ # ``aud`` last: the caller's body must never choose which endpoint the
+ # signature is valid for.
+ full_body = {
+ **payload.body,
+ "ts_ms": int(time.time() * 1000),
+ AUDIENCE_FIELD: signed_audience("POST", payload.path),
+ }
body_bytes = canonical_json(full_body)
headers = _signed_headers(privkey, pubkey, full_body)
async with httpx.AsyncClient(timeout=10.0) as c:
@@ -263,7 +276,11 @@ async def proxy_patch(request: Request, payload: ProxyPatchRequest) -> Any:
backend = _backend_url(request)
kr = _KeyringBackend()
privkey, pubkey = _load_or_create_privkey(kr)
- full_body = {**payload.body, "ts_ms": int(time.time() * 1000)}
+ full_body = {
+ **payload.body,
+ "ts_ms": int(time.time() * 1000),
+ AUDIENCE_FIELD: signed_audience("PATCH", payload.path),
+ }
body_bytes = canonical_json(full_body)
headers = _signed_headers(privkey, pubkey, full_body)
async with httpx.AsyncClient(timeout=10.0) as c:
diff --git a/tests/board/test_federation_proxy_audience.py b/tests/board/test_federation_proxy_audience.py
new file mode 100644
index 0000000000..04c9c594c6
--- /dev/null
+++ b/tests/board/test_federation_proxy_audience.py
@@ -0,0 +1,119 @@
+"""The board federation proxy signs every request for ONE backend endpoint.
+
+The backend refuses a signature whose ``aud`` does not name the route it
+arrives at (``board_backend.auth._check_audience``); these tests drive the
+proxy routes against the real backend app over ``httpx.ASGITransport``.
+"""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+from types import SimpleNamespace
+from typing import Any
+
+import httpx
+import pytest
+
+pytest.importorskip(
+ "board_backend",
+ reason="board-backend module not on sys.path (public snapshot / plain checkout)",
+)
+from board_backend.config import Settings # noqa: E402
+from board_backend.crypto import generate_keypair # noqa: E402
+from board_backend.main import create_app # noqa: E402
+from fastapi import FastAPI # noqa: E402
+
+from jarvis.ui.web import federation_proxy_routes as proxy # noqa: E402
+
+_BACKEND = "http://backend"
+_ADMIN = "test-admin" # noqa: S105 - fixture value for a throwaway in-memory backend
+# The proxy builds its client from the shared ``httpx`` module, so the tests
+# patch that attribute; their own client must be the real class.
+_RealAsyncClient = httpx.AsyncClient
+
+
+def keypair() -> tuple[str, str]:
+ return generate_keypair()
+
+
+def backend(tmp_path: Path, keypair: tuple[str, str]) -> FastAPI:
+ app = create_app(
+ settings=Settings(
+ admin_token=_ADMIN,
+ db_path=tmp_path / "backend.db",
+ register_rate_limit_per_minute=100,
+ replay_window_seconds=300,
+ )
+ )
+ app.state.disable_background = True
+ return app
+
+
+def _proxy_app(monkeypatch: pytest.MonkeyPatch, keypair: tuple[str, str],
+ transport: httpx.AsyncBaseTransport) -> FastAPI:
+ def _client(*_args: Any, **kwargs: Any) -> httpx.AsyncClient:
+ return _RealAsyncClient(transport=transport, timeout=kwargs.get("timeout", 10.0))
+
+ monkeypatch.setattr(proxy.httpx, "AsyncClient", _client)
+ monkeypatch.setattr(proxy, "_KeyringBackend", lambda: None)
+ monkeypatch.setattr(proxy, "_load_or_create_privkey", lambda _kr: keypair)
+ app = FastAPI()
+ app.include_router(proxy.router)
+ app.state.config = SimpleNamespace(
+ board=SimpleNamespace(federation=SimpleNamespace(backend_url=_BACKEND))
+ )
+ return app
+
+
+async def _call(app: FastAPI, method: str, url: str, **kwargs: Any) -> httpx.Response:
+ async with _RealAsyncClient(
+ transport=httpx.ASGITransport(app=app), base_url="http://jarvis"
+ ) as client:
+ return await client.request(method, url, **kwargs)
+
+
+async def test_proxied_get_is_accepted_by_the_backend(
+ monkeypatch: pytest.MonkeyPatch, backend: FastAPI, keypair: tuple[str, str]
+) -> None:
+ _, pub = keypair
+ async with httpx.AsyncClient(
+ transport=httpx.ASGITransport(app=backend), base_url=_BACKEND
+ ) as admin:
+ registered = await admin.post(
+ "/api/v1/identity/register",
+ json={"pubkey": pub, "display_name": "Owner"},
+ headers={"X-Admin-Token": _ADMIN},
+ )
+ assert registered.status_code == 200, registered.text
+
+ app = _proxy_app(monkeypatch, keypair, httpx.ASGITransport(app=backend))
+ resp = await _call(app, "GET", "/api/board/federation/get", params={"path": "/api/v1/me"})
+ assert resp.status_code == 200, resp.text
+ assert resp.json()["pubkey"] == pub
+
+
+async def test_caller_body_cannot_choose_the_signed_endpoint(
+ monkeypatch: pytest.MonkeyPatch, keypair: tuple[str, str]
+) -> None:
+ """The UI supplies the body; a smuggled ``aud`` would let it obtain a
+ signature for a different endpoint than the allow-listed path."""
+ seen: list[dict[str, Any]] = []
+
+ def _handler(request: httpx.Request) -> httpx.Response:
+ seen.append(json.loads(request.content))
+ return httpx.Response(200, json={"ok": True})
+
+ app = _proxy_app(monkeypatch, keypair, httpx.MockTransport(_handler))
+ resp = await _call(
+ app,
+ "POST",
+ "/api/board/federation/post",
+ json={"path": "/api/v1/activities", "body": {"aud": "GET /api/v1/friends", "x": 1}},
+ )
+ assert resp.status_code == 200, resp.text
+ assert seen[0]["aud"] == "POST /api/v1/activities"