Repository navigation
feat(webhooks): add webhook payload size limits and oversized handling policy (#674) - #716
Open
chiragjangiir wants to merge 1 commit into
Open
chiragjangiir wants to merge 1 commit into
chiragjangiir wants to merge 1 commit into
Conversation
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.
Summary
Resolves #674 by introducing configurable webhook payload size limits, pre-buffering stream defenses, safe truncation and fail-closed rejection policies, structured error responses, and end-to-end boundary tests.
Root Cause / Context
Webhook endpoints lacked payload byte-level bounds and pre-buffering enforcement, creating risks of unbounded memory consumption or inconsistent error semantics when receiving oversized payloads.
Changes
WEBHOOK_MAX_PAYLOAD_BYTES(default: 256 KB) andWEBHOOK_OVERSIZED_POLICY(reject[default] ortruncate) toConfiginapp/config.pyand documented in.env.example.app/services/webhook_payloads.py):read_webhook_streamwith pre-buffering enforcement: evaluatesContent-Lengthheaders before body reads, and aborts chunked streams exceeding limits to prevent excessive memory buffering.enforce_payload_size:rejectpolicy: fails closed with HTTP 413 and structured error details (payload_too_large).truncatepolicy: safely truncates voluminous non-essential fields (diff,raw,content,findings, etc.) while ensuring core immutable envelope fields (id,event_type,timestamp,workspace_id) are never corrupted; adds explicit_truncated: Truemetadata.malformed_payload,empty_payload), 401 (unauthorized), 413 (payload_too_large), 422 (invalid_payload).@require_webhook_payload_limitview decorator.app/webhooks/):webhooksblueprint withGET /api/webhooks/policyandPOST /api/webhooks/events.docs/webhooks.md):tests/test_webhook_payload_limits.py):Verification
pytest tests/test_webhook_payload_limits.py tests/test_event_wiring.py tests/test_events.py -v: 54/54 passed.ruff check .: All checks passed.black --check .: All checks passed.