Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coven_github_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def read_request_body(environ):
length = -1
if length > MAX_WEBHOOK_BODY_BYTES:
raise PayloadTooLarge
if length > 0:
if length >= 0:
return environ["wsgi.input"].read(length)
body = environ["wsgi.input"].read(MAX_WEBHOOK_BODY_BYTES + 1)
if len(body) > MAX_WEBHOOK_BODY_BYTES:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_webhook_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ def test_webhook_reads_body_when_content_length_is_unparsable(self):
self.assertEqual(status, "200 OK")
self.assertTrue(payload["ok"])

def test_webhook_treats_zero_content_length_as_empty_body(self):
with tempfile.TemporaryDirectory() as tmp:
from pathlib import Path

secret = "zero-length-secret"
adapter = import_adapter(Path(tmp), secret)

status, payload = self.call_app(
adapter,
b'{"zen":"Keep it logically awesome."}',
{
"X-GitHub-Event": "ping",
"X-GitHub-Delivery": "delivery-zero-length",
"X-Hub-Signature-256": signature(secret, b""),
},
content_length=0,
)

self.assertEqual(status, "400 Bad Request")
self.assertEqual(payload["error"], "invalid json")

def test_webhook_rejects_oversized_content_length_before_signature_check(self):
with tempfile.TemporaryDirectory() as tmp:
from pathlib import Path
Expand Down