Repository navigation
Add extras: real_ip plugin, Discord solve bot, Python challenge sync - #8
Merged
CorentinFelten merged 1 commit intoNov 10, 2026
Conversation
- extras/real_ip: CTFd plugin appending Cloudflare ranges to TRUSTED_PROXIES so Tracking, logs and rate limits see the real client IP behind Cloudflare (with the matching Traefik trustedIPs setup). - extras/solve-bot: posts solves and first bloods to Discord (webhook or bot token), never counting admins/hidden/SKIP_USERS, with persisted state so restarts do not re-announce. - extras/ctfd-sync: idempotent sync of challenge.yml / challenge-*.yml into CTFd (challenges, flags, hints, tags, prerequisites, bilingual descriptions/hints, optional event configs), plus an in-container uploader for challenge files. Used for UnitedCTF 2026; credentials and event settings moved to environment variables / an optional JSON file.
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
This PR adds three opt-in tools we used to run UnitedCTF 2026 on the CTFd + Zync + Galvanize stack. Each lives in its own folder under
extras/, andextras/README.mdexplains how to set it up in adeploy/folder created bysetup.sh.setup.shitself and the default deployment are unchanged.Related: 28Pollux28/galvanize#7 and 28Pollux28/zync#1.
extras/real_ip: real client IPs behind CloudflareProblem: when the CTFd domain is proxied by Cloudflare, Admin → Tracking, the gunicorn logs and the IP-based rate limits all record Cloudflare edge addresses (
172.69.*,162.158.*, …). That happens for two reasons:X-Forwarded-Forwith the edge address.TRUSTED_PROXIESonly covers private ranges by default, soget_ip()stops at the Cloudflare hop.Fix:
TRUSTED_PROXIESwhen CTFd loads.forwardedHeaders.trustedIPssetting, and recommends againstinsecure: true.REVERSE_PROXY=2,1,1,1,1setting, so gunicorn's access log shows the real client too.extras/solve-bot: Discord solve and first-blood announcements/api/v1/submissions?type=correctand posts each new solve in French and English, with its rank and a 🩸 FIRST BLOOD message for the first solver.User-Agent, because Discord returns 403 for urllib's default one.SKIP_USERSare neither announced nor counted. CTFd's API returns 404 for hidden and admin users, and the bot treats that as staff. Before this, a hidden admin's test solve was announced as first blood.STATE_PATH. On its first start the bot catches up on existing solves without posting them.BOT_USERNAMEandSKIP_CHALLENGES.extras/ctfd-sync: Python challenge syncctfd_sync.py: syncs everychallenge.ymland numberedchallenge-*.ymlinto CTFd through the admin API. Running it again only adds what's missing.requirements, by challenge name.{fr, en}descriptions and hints are supported.zyncstayszync; everything else becomesstandard./api/v1/configsfrom a JSON file.ctfd_upload_inside.py: attaches the files listed in the manifest written by the sync. It runs inside the CTFd container and uses CTFd's ownupload_file(), which avoids proxy request-size limits.CTFD_URL,CTFD_HOST,CTFD_ADMIN_*,CHALLENGE_DIR,MANIFEST_PATH,CTFD_CONFIGS_JSON). The original scripts had credentials, paths and event dates written into the code.This overlaps with
challenges.sh sync. It's offered as an alternative for repositories that use bilingual fields or several challenges per folder, which matches Galvanize'schallenge-*.ymlandinstance_groupsupport.Also
README.mdandREADME_FR.mdeach get a short "Extras" entry pointing toextras/README.md..gitignorenow ignores__pycache__/.Test plan
python3 -m py_compilepasses on every script.ctfd_sync.load_all()parses a samplechallenge-1.ymlwith bilingual description and hints. The sync refuses to run withoutCHALLENGE_DIR.real_ip+ TraefiktrustedIPson a deployment made withsetup.shbehind Cloudflare