Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Exempt server-side recording-session chunk endpoints from the global IP rate limit so multi-hour recordings aren't throttled mid-session

Murtaza Nasir101394620ef5
diff --git a/src/app.py b/src/app.py
index a7bfee51..f7f9d886 100644
--- a/src/app.py
+++ b/src/app.py
@@ -474,6 +474,17 @@ def exempt_status_endpoints():
# Exempt job queue status polling (polled every 5-30 seconds during processing)
if request.path == '/api/recordings/job-queue-status' and request.method == 'GET':
return True
+ # Exempt server-side recording-session endpoints (#287). These are the
+ # RECOMMENDED path for multi-hour recordings, which stream one chunk every
+ # few seconds — at the default 5s cadence a recording emits ~720 chunks/hour,
+ # and the global IP limit (1000/hour, 5000/day) is shared with all the
+ # user's other requests, so a long session would otherwise start getting
+ # 429'd partway through and lose its streaming guarantee. The endpoints are
+ # login-protected, ownership-checked, and already bounded per user by
+ # RECORDING_SESSION_MAX_BYTES_PER_USER / RECORDING_SESSION_MAX_CHUNK_BYTES,
+ # so IP-based rate limiting is the wrong control here.
+ if request.path.startswith('/upload/session'):
+ return True
return False
csrf = CSRFProtect(app)
diff --git a/tests/test_security_audit_fixes.py b/tests/test_security_audit_fixes.py
index 65a9de7e..cfed5ec6 100644
--- a/tests/test_security_audit_fixes.py
+++ b/tests/test_security_audit_fixes.py
@@ -216,6 +216,28 @@ def test_webhook_delivery_allows_public_host():
assert error is None
+# ---------------------------------------------------------------------------
+# Long recordings must not be throttled by the global IP rate limit
+# ---------------------------------------------------------------------------
+
+
+def test_recording_session_chunk_uploads_are_rate_limit_exempt():
+ """The server-side recording-session endpoints (the recommended path for
+ multi-hour recordings) must be exempt from the global IP rate limit, or a
+ long session's ~720 chunks/hour would start getting 429'd partway through."""
+ from src.app import exempt_status_endpoints
+
+ chunk_path = "/upload/session/2b6a-uuid/chunks/842"
+ finalize_path = "/upload/session/2b6a-uuid/finalize"
+ with app.test_request_context(chunk_path, method="POST"):
+ assert exempt_status_endpoints() is True
+ with app.test_request_context(finalize_path, method="POST"):
+ assert exempt_status_endpoints() is True
+ # A regular (non-session) endpoint must NOT be blanket-exempted.
+ with app.test_request_context("/api/recordings", method="GET"):
+ assert exempt_status_endpoints() is not True
+
+
if __name__ == "__main__":
failures = 0
for name, fn in sorted(globals().items()):