Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bf7f57b

Browse files
committedFeb 13, 2025·
Set upload limits consistently
We previously checked that the content was below GitHub's 25M limit, but this was done in the request handler. `aiohttp` _already_ checks the content size and has a limit of 1 MiB. Instead, set the limit for `aiohttp` and for Caddy directly. Though the latter is redundant, it's possibly a bit more secure. Limiting upload to the regular site is also probably redundant since it goes to `file_server` which supports no uploads, but better to cut that off early. CloudFlare also has a limit set, but it's to its minimum allowed which is 100MB.
1 parent 471195e commit bf7f57b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
 

Diff for: ‎templates/Caddyfile.j2

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ http://{{ caddy.addresses.webhook }} {
3333

3434
root * {{ caddy.site_dir }}
3535

36+
request_body {
37+
max_size 25MB # Limit from GitHub.
38+
}
39+
3640
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#delivery-headers
3741
@valid_webhook {
3842
path /gh/*
@@ -85,6 +89,10 @@ http://{{ caddy.addresses.main }}, http://{{ ansible_fqdn }} {
8589

8690
root * {{ caddy.site_dir }}
8791

92+
request_body {
93+
max_size 0
94+
}
95+
8896
{% for site, path in repos.items() %}
8997
import subproject {{ site }} {{ path | default(site, true) }}
9098
{% endfor %}

Diff for: ‎webhook/webhook.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ async def github_webhook(request: web.Request):
8888
8989
We only handle ping and push events (this is enforced by the Caddyfile).
9090
"""
91-
# Verify some input parameters.
92-
if request.content_length > 25_000_000: # Limit from GitHub.
93-
raise web.HTTPBadRequest(reason='Request too large')
94-
9591
# This should be guarded against by Caddy, but check anyway.
9692
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#delivery-headers
9793
try:
@@ -183,7 +179,7 @@ def create_app():
183179
site_dir = Path(os.environ.get('SITE_DIR', 'sites')).resolve()
184180
assert site_dir.is_dir()
185181

186-
app = web.Application()
182+
app = web.Application(client_max_size=25_000_000) # Limit from GitHub.
187183
app['site_dir'] = site_dir
188184
app.add_routes([
189185
web.post('/gh/{repo}', github_webhook),

0 commit comments

Comments
 (0)
Please sign in to comment.