Skip to content

Templates ​

Files ending in .plf are templates: before an instance starts, the platform renders them for the team that owns it and drops the extension. docker-compose.yml.plf becomes docker-compose.yml, data/config.json.plf becomes data/config.json. The template language is Tera (similar to Jinja2), so you can use variables, conditions and loops:

YAML
# docker-compose.yml.plf
services:
    web:
        build: .
        environment:
            FLAG: "{{ flag() }}"
            TEAM: "{{ actor }}"
{% if not is_export %}
            DEBUG: "false"
{% endif %}

Templates are rendered in two situations:

Situationactoris_export
Starting an instanceThe team that owns itfalse
Downloading a handout or attachmentThe team downloading ittrue

actor is team-<team slug> in team CTFs and user-<username> otherwise.

TIP

Files used to have the extension .plftera. It still works, but ctfgarden lint suggests renaming them.

Built-in functions ​

flag() ​

The team's flag, for challenges with actor_flag in their metadata. In handouts and attachments (is_export), it returns a fake flag in the same format that isn't valid for anyone. Rendering fails if the challenge has no actor_flag.

Don't build flags from actor yourself (like ctf{team-foo}): other teams can guess them. flag() can't be guessed, and lets the platform detect flag sharing.

canary() ​

The team's canary token with the given name, 32 hex characters:

YAML
environment:
    ADMIN_PASSWORD: "{{ canary(name='admin-password') }}"
    API_KEY: "{{ canary(name='api-key', force_identical=true) }}"
ArgumentDescription
nameRequired. List it in canaries in the metadata, or it isn't detected
force_identicalOptional, false by default. Handouts and attachments get a different value than the instance, so players can't read the secret from the handout. Set it to true if the handout needs the instance's value

The same team always gets the same value for a challenge and name, different teams get different values.

WARNING

Images built by the platform are shared by all teams, so templates in a build context are rendered without a team. Pass per-team values to the container at runtime instead: as environment variables in the compose file, or through the data directory.

JS extensions ​

Add your own template functions in JavaScript. Every .js file in a _ctfgarden directory is loaded before the templates next to it are rendered:

js
// _ctfgarden/helpers.js
registerPlfHandler("shout", (args) => args.text.toUpperCase());
{{ shout(text="hello") }}

registerPlfHandler(name, handler, isSafe?) registers handler(args: Record<string, string>) => string as the function name. Set isSafe to true if its output shouldn't be escaped.

The _ctfgarden directory is looked up next to the file being rendered, so a template in data/ needs its own data/_ctfgarden. Extensions are loaded once per directory, so global variables in them are shared by all templates of that directory. It's never part of handouts. Extensions run in Boa, with crypto.getRandomValues and crypto.randomUUID from the Web Crypto API, but without file or network access.

Imprint