[AZ-178] Fix Critical/High security findings: auth, CVEs, non-root containers, per-job SSE

- Pin all deps; h11==0.16.0 (CVE-2025-43859), python-multipart>=1.3.1 (CVE-2026-28356), PyJWT==2.12.1
- Add HMAC JWT verification (require_auth FastAPI dependency, JWT_SECRET-gated)
- Fix TokenManager._refresh() to use ADMIN_API_URL instead of ANNOTATIONS_URL
- Rename POST /detect → POST /detect/image (image-only, rejects video files)
- Replace global SSE stream with per-job SSE: GET /detect/{media_id} with event replay buffer
- Apply require_auth to all 4 protected endpoints
- Fix on_annotation/on_status closure to use mutable current_id for correct post-upload event routing
- Add non-root appuser to Dockerfile and Dockerfile.gpu
- Add JWT_SECRET to e2e/docker-compose.test.yml and run-tests.sh
- Update all e2e tests and unit tests for new endpoints and HMAC token signing
- 64/64 tests pass

Made-with: Cursor
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-04-02 06:32:12 +03:00
parent dac350cbc5
commit 097811a67b
25 changed files with 369 additions and 429 deletions
+4 -4
View File
@@ -33,14 +33,14 @@ class TestHealthEngineStep01PreInit:
@pytest.mark.cpu
@pytest.mark.slow
class TestHealthEngineStep02LazyInit:
def test_ft_p_14_lazy_initialization(self, http_client, image_small):
def test_ft_p_14_lazy_initialization(self, http_client, image_small, auth_headers):
before = _get_health(http_client)
assert before["aiAvailability"] == "None", (
f"engine already initialized (aiAvailability={before['aiAvailability']}); "
"lazy-init test must run before any test that triggers warm_engine"
)
files = {"file": ("lazy.jpg", image_small, "image/jpeg")}
r = http_client.post("/detect", files=files, timeout=_DETECT_TIMEOUT)
r = http_client.post("/detect/image", files=files, headers=auth_headers, timeout=_DETECT_TIMEOUT)
r.raise_for_status()
body = r.json()
assert isinstance(body, list)
@@ -60,9 +60,9 @@ class TestHealthEngineStep03Warmed:
_assert_active_ai(data)
assert data.get("errorMessage") is None
def test_ft_p_15_onnx_cpu_detect(self, http_client, image_small):
def test_ft_p_15_onnx_cpu_detect(self, http_client, image_small, auth_headers):
files = {"file": ("onnx.jpg", image_small, "image/jpeg")}
r = http_client.post("/detect", files=files, timeout=_DETECT_TIMEOUT)
r = http_client.post("/detect/image", files=files, headers=auth_headers, timeout=_DETECT_TIMEOUT)
r.raise_for_status()
body = r.json()
assert isinstance(body, list)