Metadata and flags
Everything about a challenge that isn't about running it goes into the x-ctf-metadata block of the compose file.
Fields
x-ctf-metadata:
name: Login Bypass
authors: [Alice, Bob]
description_md: |
Can you log in as **admin**?
difficulty: medium
categories: [web]
flag: ctf{sql_injection}| Field | Required | Description |
|---|---|---|
name | Yes | Name shown to players |
authors | Yes | List of authors |
description_md | Yes | Description, in Markdown |
difficulty | Yes | One of the difficulties defined in event.yml |
flag, actor_flag or flag_validation_fn | One of them | The flag |
categories | No | Categories defined in event.yml |
attachments | No | Files players can download, relative to the compose file. See attachments |
auto_publish_src | No | Offer the whole challenge directory as a handout. Defaults to false |
release_time | No | Unix timestamp from which players can see and solve the challenge |
end_time | No | Unix timestamp after which the challenge can't be solved anymore |
instance_timeout_minutes | No | How long an instance runs before it's stopped |
allow_extend_time | No | Whether players can extend the time of their instance. Defaults to true |
data_pvc_size | No | Size of the data directory volume, e.g. 100Mi |
canaries | No | Names of the canary tokens the challenge uses |
decoy | No | Makes this a decoy challenge |
additional_metadata | No | Anything you like, for example for a custom points function |
Unknown fields are ignored, ctfgarden lint warns about them (they're usually typos).
Authors and admins can see and test challenges before their release_time and after their end_time.
Flags
Set exactly one of these:
| Field | Description |
|---|---|
flag | A fixed flag, the same for everyone |
actor_flag | A flag per team, generated by the platform |
flag_validation_fn | A JavaScript validation function |
If you set more than one, only the first one in this order is used, and ctfgarden lint warns.
Quote flags that YAML would read as something else, like numbers (flag: "1234"). Check whether a flag is accepted with ctfgarden lint --flag 'ctf{...}'.
Per-team flags
With actor_flag, every actor (every team in team CTFs, every user otherwise) gets their own flag. The value is a format that contains {token} exactly once:
x-ctf-metadata:
# ...
actor_flag: "ctf{sql_injection_{token}}"The platform replaces {token} with 16 hex characters derived from the challenge ID, the actor and the platform's secret key. Nobody can compute another actor's flag.
Pass the flag to your challenge with flag() in a template, for example in docker-compose.yml.plf:
services:
web:
build: .
environment:
FLAG: "{{ flag() }}"In handouts and attachments, flag() returns a fake flag in the same format, so a handout never contains a real flag. If an actor submits another actor's flag, the submission is rejected and both get a flag sharing suspicion event.
WARNING
In templates, {{ starts an expression. If your format has {token} right after the opening brace of the flag, put a fixed part in between (ctf{x_{token}}), or keep the metadata in a plain docker-compose.yml.
Validation functions
For flags that can't be compared as a string, write a JavaScript function. It runs in the same Boa runtime as JS extensions:
x-ctf-metadata:
# ...
flag_validation_fn: |
setFlagValidationFunction((flag) => {
return flag.toLowerCase() === "ctf{case_does_not_matter}";
});The function receives the submitted flag and returns:
| Return value | Meaning |
|---|---|
true | Valid for everyone |
false | Invalid |
| A string | Valid, but only for the actor returned (team-<slug> or user-<username>). If that's not the submitting actor, the platform reports flag sharing |
Returning anything else is an error. ctfgarden lint runs the function once, so syntax errors show up before players submit flags.
If you need per-team flags in your own format, generate them in a JS extension and return the actor from the validation function:
// _ctfgarden/flag.js
const SECRET = "change-me";
// FNV-1a, good enough to make flags hard to guess, but not cryptographically secure
function sign(actor) {
let hash = 0x811c9dc5;
for (const c of SECRET + actor) {
hash ^= c.charCodeAt(0);
hash = Math.imul(hash, 0x01000193) >>> 0;
}
return hash.toString(16).padStart(8, "0");
}
registerPlfHandler("my_flag", (args) => `ctf{${sign(args.actor)}_${args.actor}}`);# docker-compose.yml.plf
services:
web:
environment:
FLAG: "{{ my_flag(actor=actor) }}"
x-ctf-metadata:
# ...
flag_validation_fn: |
const SECRET = "change-me";
function sign(actor) { /* same as above */ }
setFlagValidationFunction((flag) => {
const match = flag.match(/^ctf\{([0-9a-f]{8})_(.+)\}$/);
if (!match || sign(match[2]) !== match[1]) {
return false;
}
return match[2];
});WARNING
Only return an actor for flags your function generated itself. If it returns an actor for any flag in the right format, players can forge a flag for their own team.
The _ctfgarden directory and x-ctf-metadata are never part of handouts, so the secret is safe there, but nowhere else in the challenge directory.
Canaries
Canaries are per-team values for the intermediate secrets of a challenge, like passwords, API keys or cookies. If one team's canary shows up in the traffic to another team's instance, the traffic agent reports it, even if the final flag is the same for everyone. See canaries.
Generate them with canary(), and list every name in canaries. Only listed canaries are detected:
# docker-compose.yml.plf
services:
web:
environment:
ADMIN_PASSWORD: "{{ canary(name='admin-password') }}"
x-ctf-metadata:
# ...
canaries:
- admin-passwordCanaries are only detected if players send them to the instance unchanged and in plaintext through the ingress, for example in an HTTP request.
Decoy challenges
Set decoy: true to make a challenge a honeypot for LLM agents. The frontend hides decoys from human players, so starting, submitting a flag for or solving one is a strong sign of an agent. Decoys need a flag like every other challenge. See decoy challenges.