Rate-limit report ingestion per host

Reports arriving sooner than report_min_interval_seconds (default 30) after
the host's previous one are refused with 429 and a Retry-After header. The
check shares the insert's transaction so concurrent requests can't bypass it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Sonnet 5.5 committed 2026-10-29 20:46:09 -04:00
1 parent 8cb7ef5e8b
commit a6a43b142f
6 files changed
+71 -3

No files matched your search

+5 -1
View File
@@ -334,9 +334,13 @@ class Handler(BaseHTTPRequestHandler):
report = sanitize(json.loads(body))
except (ValueError, ReportError) as exc:
return self.send_json(HTTPStatus.BAD_REQUEST, {"error": str(exc)})
db.add_report(conn, host, report, self.cfg.report_retention_days)
wait = db.add_report(conn, host, report, self.cfg.report_retention_days,
self.cfg.report_min_interval_seconds)
finally:
conn.close()
if wait:
return self.send(HTTPStatus.TOO_MANY_REQUESTS, json.dumps({"error": "reporting too often"}),
"application/json", {"Retry-After": str(wait)})
self.send(HTTPStatus.NO_CONTENT, b"", "text/plain")
# -- auth pages --