Repository navigation
Protect public demo from admin crawler traffic - #36
Merged
Merged
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
The public demo became intermittently unavailable while crawlers sent hundreds of requests per minute to Django admin pages. Add crawler guidance and enforce admin request limits at Caddy so excess traffic is rejected before it reaches Gunicorn. Cloudflare now proxies the demo hostname and challenges
/staff-admin/; this PR also closes the direct-origin bypass for that route.Changes
robots.txtthat disallows/staff-adminfor cooperative crawlers.caddy-ratelimitrevision. Production and development continue using stock Caddy.Caddyfile.sharedin the production and demo entry files, so demo crawler rules stay separate without duplicating those routes.CF-Connecting-IPheader for the visitor limit, after rejecting admin requests whose immediate peer is outside Cloudflare's published IP ranges..localhosttesting to selectCaddyfile.devthroughDEMO_CADDYFILE; the public demo defaults toCaddyfile.demoeven if its existing.envnamesCaddyfile.prod.Testing
docker compose -f docker-compose.base.yml -f docker-compose.demo.yml build caddydocker compose --env-file .env.demo.example -f docker-compose.base.yml -f docker-compose.demo.yml config --quietactionlint .github/workflows/deploy-demo.ymlCaddyfile.demoandCaddyfile.shared.robots.txtreturned the disallow rule; repeated admin requests returned HTTP 429 at the per-IP cap; direct admin requests returned HTTP 403 even with a forged visitor-IP header; and two simulated Cloudflare visitors received separate rate-limit buckets.Valid configuration).python -m unittest tests.test_cloudflare_ip_check -v: 3 passed.actionlint .github/workflows/check-cloudflare-ips.yml: passed.python runtests.py: 227 passed.Risks and deployment
.envedit is required./staff-admin/Managed Challenge rule enabled. The direct-origin restriction takes effect only after this PR is merged and deployed.