Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

🔒️(summary) sanitize upstream HTTP failures

Florent Chehabfcd37b0f266a
diff --git a/src/summary/summary/core/celery_worker.py b/src/summary/summary/core/celery_worker.py
index 5d7a7056..c1ee5ce2 100644
--- a/src/summary/summary/core/celery_worker.py
+++ b/src/summary/summary/core/celery_worker.py
@@ -171,9 +171,9 @@ def transcribe_audio(
try:
res.raise_for_status()
except requests.exceptions.HTTPError:
- logger.exception("WhisperX transcription failed")
+ logger.error("WhisperX transcription failed")
# We reraise the error so that it can be retried by celery
- raise
+ raise requests.exceptions.HTTPError("WhisperX request failed") from None
transcription_json: dict[str, Any] = res.json()
# We remove the "usage" key from the transcription_json dictionary
@@ -213,7 +213,7 @@ def transcribe_audio(
redacted_cloud_storage_url = (
redact_url(cloud_storage_url) if cloud_storage_url else None
)
- logger.exception(
+ logger.error(
("Unexpected error while preparing file %s "),
redacted_cloud_storage_url,
)
@@ -253,21 +253,18 @@ def resolve_speaker_identities_and_apply_to(
new_transcription = speaker_mapping.apply_to(transcription.model_dump())
return WhisperXResponse.model_validate(new_transcription)
- except FileServiceException as exc:
+ except FileServiceException:
logger.error(
- "Error reading metadata for task %s; skipping speaker assignment."
- " Error: %s",
+ "Error reading metadata for task %s; skipping speaker assignment.",
task_id,
- exc,
)
return transcription
- except Exception as exc:
- logger.exception(
+ except Exception:
+ logger.error(
"resolve_speaker_identities failed for task %s; skipping"
- " speaker assignment. Error: %s",
+ " speaker assignment.",
task_id,
- exc,
)
return transcription
diff --git a/src/summary/summary/core/docs_service.py b/src/summary/summary/core/docs_service.py
index 96c5f130..63dd6af6 100644
--- a/src/summary/summary/core/docs_service.py
+++ b/src/summary/summary/core/docs_service.py
@@ -4,7 +4,7 @@ import json
import logging
from urllib.parse import urljoin
-from requests import Session
+from requests import RequestException, Session
from requests.adapters import HTTPAdapter
from urllib3.util import Retry
@@ -43,6 +43,8 @@ def _post_with_retries(*, url, data, api_key: str | None = None):
response = session.post(url, json=data, timeout=(20, 3 * 60))
response.raise_for_status()
return response
+ except RequestException:
+ raise RequestException("Docs delivery failed") from None
finally:
session.close()
diff --git a/src/summary/summary/core/file_service.py b/src/summary/summary/core/file_service.py
index 0ba36ebe..b41412cb 100644
--- a/src/summary/summary/core/file_service.py
+++ b/src/summary/summary/core/file_service.py
@@ -353,10 +353,10 @@ class FileService:
logger.debug("Recording local file path: %s", local_path)
return local_path
- except requests.RequestException as e:
+ except requests.RequestException:
raise FileServiceException(
"Unexpected error while downloading object from cloud_storage_url."
- ) from e
+ ) from None
def _validate_duration(self, duration_seconds: float) -> None:
"""Validate audio file duration against configured maximum."""
diff --git a/src/summary/summary/core/webhook_service.py b/src/summary/summary/core/webhook_service.py
index 3ccb8618..f63a8936 100644
--- a/src/summary/summary/core/webhook_service.py
+++ b/src/summary/summary/core/webhook_service.py
@@ -30,16 +30,19 @@ def call_webhook_v2(
logger.debug("Submitting to %s", tenant.webhook_url)
logger.debug("Request payload: %s", payload.model_dump_json(indent=2))
- response = requests.post(
- tenant.webhook_url,
- json=dump_for_transport(payload),
- headers={
- "Authorization": f"Bearer {tenant.webhook_api_key.get_secret_value()}",
- "User-Agent": settings.app_external_user_agent,
- },
- timeout=(10, 20),
- )
- response.raise_for_status()
+ try:
+ response = requests.post(
+ tenant.webhook_url,
+ json=dump_for_transport(payload),
+ headers={
+ "Authorization": f"Bearer {tenant.webhook_api_key.get_secret_value()}",
+ "User-Agent": settings.app_external_user_agent,
+ },
+ timeout=(10, 20),
+ )
+ response.raise_for_status()
+ except requests.RequestException:
+ raise requests.RequestException("Webhook delivery failed") from None
try:
response_data = response.json()
diff --git a/src/summary/tests/conftest.py b/src/summary/tests/conftest.py
index f24f8db5..7e1e2928 100644
--- a/src/summary/tests/conftest.py
+++ b/src/summary/tests/conftest.py
@@ -22,6 +22,12 @@ def get_settings_override():
)
+def settings_override():
+ """Provide isolated settings containing the test tenant."""
+ return get_settings_override()
+
+
@pytest.fixture()
def client():
"""Provide a FastAPI TestClient for tests."""
diff --git a/src/summary/tests/unit/test_privacy.py b/src/summary/tests/unit/test_privacy.py
index 6c72b298..044f4278 100644
--- a/src/summary/tests/unit/test_privacy.py
+++ b/src/summary/tests/unit/test_privacy.py
@@ -1,11 +1,14 @@
"""Regression tests for observability privacy boundaries."""
+import logging
from unittest.mock import Mock
import pytest
+import requests
-from summary.core import analytics
+from summary.core import analytics, webhook_service
from summary.core.privacy import redact_url
+from summary.core.shared_models import SummarizeWebhookSuccessPayload
CANARY = "sensitive-canary"
URL = f"https://user:[email protected]/file?signature={CANARY}#fragment"
@@ -16,6 +19,52 @@ def test_url_redaction():
assert redact_url(URL) == "https://example.com/file?[redacted]"
[email protected]("log_level", [logging.DEBUG, logging.INFO])
+def test_webhook_content_is_only_logged_at_debug(
+ monkeypatch, caplog, settings_override, log_level
+):
+ """DEBUG retains response content; INFO and above only contain metadata."""
+ monkeypatch.setattr(webhook_service, "settings", settings_override)
+ response = Mock(status_code=200)
+ response.json.return_value = {"id": "document-123", "content": CANARY}
+ monkeypatch.setattr(webhook_service.requests, "post", Mock(return_value=response))
+ payload = SummarizeWebhookSuccessPayload(job_id="job", summary_data_url=URL)
+ with caplog.at_level(log_level):
+ webhook_service.call_webhook_v2(tenant_id="test-tenant", payload=payload)
+ assert (
+ webhook_service.requests.post.call_args.kwargs["json"]["summary_data_url"]
+ == URL
+ )
+ assert all(
+ CANARY not in record.getMessage()
+ for record in caplog.records
+ if record.levelno >= logging.INFO
+ )
+ if log_level == logging.DEBUG:
+ assert any(
+ record.levelno == logging.DEBUG and CANARY in record.getMessage()
+ for record in caplog.records
+ )
+ else:
+ assert CANARY not in caplog.text
+ assert "Document document-123 submitted (HTTP 200)" in caplog.text
+
+
+def test_webhook_failure_keeps_retry_category(monkeypatch, settings_override):
+ """Webhook exceptions remain retryable without upstream text."""
+ monkeypatch.setattr(webhook_service, "settings", settings_override)
+ monkeypatch.setattr(
+ webhook_service.requests,
+ "post",
+ Mock(side_effect=requests.RequestException(URL)),
+ )
+ payload = SummarizeWebhookSuccessPayload(job_id="job", summary_data_url=URL)
+ with pytest.raises(requests.RequestException) as exc:
+ webhook_service.call_webhook_v2(tenant_id="test-tenant", payload=payload)
+ assert CANARY not in str(exc.value)
+ assert exc.value.__suppress_context__
+
+
def test_analytics_source_url_removes_signature():
"""Task analytics keeps the source path without credentials or signature."""
from datetime import datetime, timezone # noqa: PLC0415