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:
1 parent
7fd2f14f91
commit
199a5efaef
12 files changed
+445
-42
No files matched your search
@@ -94,6 +94,7 @@ ERR_FEATURE_REQUIRES_AUTHGUARD = "This feature requires AUTHGUARD_URL to be conf
|
||||
# rather than a generic "internal error" indistinguishable from any other bug.
|
||||
ERR_AUTHGUARD_UNAVAILABLE = "Unable to reach the authentication service. Please try again shortly."
|
||||
ERR_SECRET_NOT_SET = "SECRET environment variable is not set."
|
||||
ERR_ADMIN_REQUIRED = "Administrator access required."
|
||||
|
||||
# _LOCAL_PROFILE is the fixed placeholder identity every handler reports when
|
||||
# authentication is disabled, either because AUTHGUARD_URL is disabled or
|
||||
@@ -338,6 +339,23 @@ def build_auth_router(
|
||||
raise HTTPException(status_code=401, detail=ERR_AUTH_REQUIRED)
|
||||
return token
|
||||
|
||||
async def require_admin(
|
||||
request: Request,
|
||||
client: Optional[AuthClient] = Depends(get_client), # noqa: B008
|
||||
) -> PublicUser:
|
||||
"""FastAPI dependency gating a route behind an administrator session
|
||||
(the Python counterpart of Go's RequireAdmin). Unlike require_session it
|
||||
never falls back to _LOCAL_PROFILE, so a route that changes the
|
||||
login-required flag cannot be called anonymously, even while login is
|
||||
already disabled."""
|
||||
if not _enabled(client):
|
||||
raise HTTPException(status_code=401, detail=ERR_AUTH_REQUIRED)
|
||||
assert client is not None
|
||||
profile, _ = await _current_profile_or_401(request, client)
|
||||
if not can_manage_users(profile.role):
|
||||
raise HTTPException(status_code=403, detail=ERR_ADMIN_REQUIRED)
|
||||
return profile
|
||||
|
||||
# --- status / me -------------------------------------------------------
|
||||
|
||||
@router.get("/me")
|
||||
@@ -561,6 +579,7 @@ def build_auth_router(
|
||||
async def update_access_settings(
|
||||
req: UpdateAccessRequest,
|
||||
store: ProxyStore = Depends(get_store), # noqa: B008
|
||||
_admin: PublicUser = Depends(require_admin), # noqa: B008
|
||||
) -> dict[str, bool]:
|
||||
nonlocal login_required_override
|
||||
await store.set_login_required(req.loginRequired)
|
||||
|
||||
Reference in new issue
Block a user