Fix high audit findings and port the hidden-media rule

Fixed findings from the audit reports (SECURITY, QUALITY, PERFORMANCE):
- P-001 · Unbounded per-session timing maps and no connection cap in the sync hub
- S-001 · Anonymous `PUT /access` switches off login for every guarded route
- S-002 · Malformed cookies crash the Node middleware and fail requests in Java
- S-004 · Anonymous `PUT /sync` writes unvalidated JSON into shared session state

Also includes the pre-existing uncommitted changes in web-ui, README, shared-styles and the .changeset files, as the owner asked.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Haiku 5.5 committed 2026-10-19 07:47:10 +00:00
1 parent 7fd2f14f91
commit 199a5efaef
12 files changed
+445 -42

No files matched your search

@@ -4,7 +4,13 @@ from fastapi import FastAPI, Request
from fastapi.testclient import TestClient
from shared_backend import authproxy as ap
from shared_backend.authclient import APIError, AuthClient, PublicUser, SessionResult
from shared_backend.authclient import (
DEFAULT_COOKIE_NAME,
APIError,
AuthClient,
PublicUser,
SessionResult,
)
class _FakeStore(ap.ProxyStore):
@@ -113,14 +119,32 @@ class AuthDisabledModeTests(unittest.TestCase):
class AccessSettingsTests(unittest.TestCase):
def test_get_and_put_round_trip_through_the_store(self) -> None:
def test_get_is_public_and_put_requires_an_admin_session(self) -> None:
store = _FakeStore(login_required=True)
client = TestClient(_build_app(store))
client = TestClient(_build_app(store, _RoleClient()))
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
response = client.put("/api/auth/access", json={"loginRequired": False})
self.assertEqual(response.status_code, 401)
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
client.cookies.set(DEFAULT_COOKIE_NAME, "user-token")
response = client.put("/api/auth/access", json={"loginRequired": False})
self.assertEqual(response.status_code, 403)
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
client.cookies.set(DEFAULT_COOKIE_NAME, "admin-token")
response = client.put("/api/auth/access", json={"loginRequired": False})
self.assertEqual(response.json(), {"loginRequired": False})
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": False})
def test_anonymous_put_is_refused_when_authguard_is_not_configured(self) -> None:
store = _FakeStore(login_required=True)
client = TestClient(_build_app(store))
response = client.put("/api/auth/access", json={"loginRequired": False})
self.assertEqual(response.status_code, 401)
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
def test_internal_update_disables_login_and_uses_admin_identity(self) -> None:
store = _FakeStore(login_required=True)
client = TestClient(
@@ -180,6 +204,16 @@ class _FakeClient(AuthClient):
return ["auth_session=; Path=/; Max-Age=0"]
class _RoleClient(_FakeClient):
"""Resolves two fixed session tokens to an administrator and an ordinary user."""
async def me(self, token: str) -> PublicUser:
roles = {"admin-token": "superadmin", "user-token": "user"}
if token not in roles:
raise APIError(401, "unauthenticated")
return PublicUser(id=1, username="a", email="a@b.com", role=roles[token])
class EnabledModeSetupAndLoginTests(unittest.TestCase):
"""Exercises the real (client is not None) path, including the
setup-claim flag's interaction with the store."""