security: устранить находки аудита, версия 1.1.7

Конфигурация и эксплуатационный слой:
- nginx: client_max_body_size 64m — восстановление из бэкапа не работало
  вовсе, дефолтный лимит в 1 МБ резал дампы (реальный экспорт ~3.4 МБ)
  с 413 ещё до backend;
- nginx: заголовки безопасности (nosniff, Referrer-Policy,
  Permissions-Policy) и полный Content-Security-Policy. Ради него
  inline-скрипт темы вынесен в public/theme-init.js;
- nginx: limit_req на /api/ — перебор пароля Basic Auth шёл со
  скоростью сети, ни блокировки, ни задержки не было;
- nginx: server_tokens off;
- порт web привязан к 127.0.0.1, адрес настраивается через
  AURUM_BIND_ADDRESS (раньше слушался на всех интерфейсах);
- backend работает от непривилегированного пользователя,
  no-new-privileges для backend и web;
- дефолты пароля Postgres сведены к одному значению в обоих сервисах,
  в .env.example описана ловушка с инициализацией тома.

Приложение:
- версия убрана из неавторизованного /api/health и отдаётся как
  app_version в GET /api/settings;
- /api/docs, /api/redoc и /api/openapi.json отключаются через
  AURUM_ENABLE_DOCS;
- текст исключения при неудачном восстановлении уходит в лог, а не
  клиенту;
- max_length для notes в схемах транзакций, активов и регулярных
  платежей (и в соответствующих полях UI);
- срок «запомнить меня» сокращён с 30 дней до 7;
- pytest обновлён до 9.0.3 (PYSEC-2026-1845), pytest-asyncio до 1.4.0;
- CI: permissions contents:read для GITHUB_TOKEN.
This commit is contained in:
ZProger
2026-09-10 21:12:31 +03:00
parent eba8add92f
commit f9413aa6e1
27 changed files with 268 additions and 78 deletions

View File

@@ -46,9 +46,12 @@ app = FastAPI(
# backend (see frontend/nginx.conf) — everything else falls through to
# the SPA's index.html, which is why the defaults (/docs, /openapi.json)
# would silently 404 through the reverse proxy.
docs_url="/api/docs",
redoc_url="/api/redoc",
openapi_url="/api/openapi.json",
# All three go away together when AURUM_ENABLE_DOCS=false — leaving
# openapi.json reachable would keep handing out the full API map even
# with the Swagger UI itself switched off.
docs_url="/api/docs" if settings.enable_docs else None,
redoc_url="/api/redoc" if settings.enable_docs else None,
openapi_url="/api/openapi.json" if settings.enable_docs else None,
)
# CORS stays off unless someone deliberately opens it, and credentials are
@@ -88,7 +91,10 @@ app.include_router(crypto.router, prefix="/api")
@app.get("/api/health")
async def health() -> dict[str, str]:
# version rides along so the frontend's Settings page can show which
# release is actually running without a separate authenticated endpoint —
# this route is already auth_basic-exempt for Docker's HEALTHCHECK.
return {"status": "ok", "version": APP_VERSION}
# Status only. This is the one route nginx serves without auth (Docker's
# HEALTHCHECK and uptime monitors need it — see frontend/nginx.conf), so
# anything returned here is world-readable. The running version used to
# ride along, which told an unauthenticated caller exactly which release
# they were looking at, and therefore which known issues it still has;
# it now comes back from GET /api/settings, which is behind auth.
return {"status": "ok"}