API server hardening#282
Merged
Merged
Conversation
gsanchietti
force-pushed
the
fix_auth
branch
2 times, most recently
from
July 15, 2026 09:53
135ec95 to
da7f974
Compare
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
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
Tbaile
approved these changes
Jul 16, 2026
edospadoni
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add per-route request body size limits to prevent unbounded uploads on authentication and ingestion endpoints.
Changes: Applied
middleware.BodyLimitwith tailored caps:Tested: Unit tests + full suite (auth/ingest routes now reject oversized bodies; pre-existing storage failures unrelated).