Repository navigation
Bound WAF request inspection and rate limiter memory - #49
Open
compnew2006 wants to merge 2 commits into
Open
compnew2006 wants to merge 2 commits into
compnew2006 wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
Problem and impact
The WAF checked a declared request size, then buffered the full body for inspection. The WAF could exceed its configured per-request inspection budget when no length was declared, putting pressure on gateway memory and affecting other requests.
The per-source rate buckets and auto-ban histories also grew with traffic and
retained entries after their clients stopped making requests.
Solution
Count actual body bytes at the ASGI receive boundary before buffering. Stop inspecting at the first chunk that would exceed
waf.max_body_bytes(1 MiB by default). Keep the early check for declared sizes.Return HTTP 413 for body-size violations in strict mode. Requests at or below the limit are replayed intact to the route. Log mode records the overflow and forwards the full stream without applying firewall auto-bans. The existing local-subnet exemption and off mode bypass inspection.
Keep the existing request checks and response security headers. Document the difference between a WAF inspection budget and each route's own upload limit.
Bound endpoint buckets and auto-ban histories separately to 4,096 entries.
Expire buckets on their route's configured window, retain only the timestamps
needed to reach the auto-ban threshold, and sweep expired state every five
seconds, including with no requests.
Preserve active counters on saturation. An untracked source on a rate-limited
route gets 429 until a slot is available. A full auto-ban table stops tracking
additional sources while the WAF continues to reject their individual violations.
Verification
pyflakes api core quota tests run.pyandgit diff --checkpassed.main.