Skip to content

API server hardening#282

Merged
gsanchietti merged 2 commits into
mainfrom
fix_auth
Jul 16, 2026
Merged

API server hardening#282
gsanchietti merged 2 commits into
mainfrom
fix_auth

Conversation

@gsanchietti

@gsanchietti gsanchietti commented Jul 13, 2026

Copy link
Copy Markdown
Member

Add per-route request body size limits to prevent unbounded uploads on authentication and ingestion endpoints.

Changes: Applied middleware.BodyLimit with tailored caps:

  • Login/2FA/logout: 1-32 KiB
  • Register/ingest: 8 KiB-8 MiB

Tested: Unit tests + full suite (auth/ingest routes now reject oversized bodies; pre-existing storage failures unrelated).

@gsanchietti gsanchietti self-assigned this Jul 13, 2026
@gsanchietti gsanchietti changed the title fix(security): bound request body size on public and semi-trusted routes API server hardening Jul 15, 2026
@gsanchietti
gsanchietti force-pushed the fix_auth branch 2 times, most recently from 135ec95 to da7f974 Compare July 15, 2026 09:53
@gsanchietti
gsanchietti requested a review from Tbaile July 16, 2026 07:07
Login, OTP-verify, unit registration, and ingest handlers bind the JSON
body before any credential check, with no size cap in the Go code and
no default limit from the Traefik reverse proxy. Concurrent large
requests could exhaust memory.

Add middleware.BodyLimit, wrapping the request body in
http.MaxBytesReader, and apply route-specific limits to /login,
/logout, /2fa/otp-verify, /units/register, and the /ingest group.

Assisted-by: Claude Code:claude-sonnet-5
@gsanchietti
gsanchietti removed the request for review from Tbaile July 16, 2026 07:09
Cap request frequency per client IP across every API route with a
token-bucket limiter, bounding the concurrent-request memory-exhaustion
vector that BodyLimit alone cannot. Trust only the local reverse-proxy
hop via SetTrustedProxies so ClientIP() resolves the real client instead
of bucketing all traffic under 127.0.0.1.

Tunable via GLOBAL_RATE_LIMIT_AVERAGE (default 25 req/s) and
GLOBAL_RATE_LIMIT_BURST (default 100); set the average to 0 to disable.

Assisted-by: Claude Code:claude-sonnet-5
@gsanchietti
gsanchietti marked this pull request as ready for review July 16, 2026 07:15
@gsanchietti
gsanchietti requested a review from Tbaile July 16, 2026 07:15
@gsanchietti
gsanchietti requested a review from edospadoni July 16, 2026 07:55
@gsanchietti
gsanchietti merged commit 862f57c into main Jul 16, 2026
11 checks passed
@gsanchietti
gsanchietti deleted the fix_auth branch July 16, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants