Skip to content

Commit b89d557

Browse files
committed
Added CFSS support and validation.
1 parent 780b7a5 commit b89d557

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

ctf/schemas/track.yaml.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@
131131
"description": "The text the participants see AFTER they submit the flag. Example: [mytrackname] 1/1 Good job! Track completed.",
132132
"minLength": 1
133133
},
134+
"cfss": {
135+
"type": "string",
136+
"description": "The CFSS string based on https://github.com/res260/cfss",
137+
"pattern": "^CFSS:[0-9]\\.[0-9][0-9]?/TS:[LBIA]/E:[LMH]/HSFC:[NY]=[0-9][0-9]?-[0-9][0-9]?$"
138+
},
134139
"tags": {
135140
"type": "object",
136141
"description": "Askgod tags for this flag. Use tag `discourse: sometriggername` to define triggers for posts in the posts/ directory.",

ctf/templates/init/schemas/track.yaml.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@
131131
"description": "The text the participants see AFTER they submit the flag. Example: [mytrackname] 1/1 Good job! Track completed.",
132132
"minLength": 1
133133
},
134+
"cfss": {
135+
"type": "string",
136+
"description": "The CFSS string based on https://github.com/res260/cfss",
137+
"pattern": "^CFSS:[0-9]\\.[0-9][0-9]?/TS:[LBIA]/E:[LMH]/HSFC:[NY]=[0-9][0-9]?-[0-9][0-9]?$"
138+
},
134139
"tags": {
135140
"type": "object",
136141
"description": "Askgod tags for this flag. Use tag `discourse: sometriggername` to define triggers for posts in the posts/ directory.",
@@ -165,4 +170,4 @@
165170
"services",
166171
"flags"
167172
]
168-
}
173+
}

ctf/templates/new/common/track.yaml.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ flags:
2626
description: Free flag in source of index.php CHANGE_ME
2727
# The text the participants see AFTER they submit the flag.
2828
return_string: '[{{ data.name }}] 1/1 Good job! Track completed. CHANGE_ME'
29+
# CFSS string based on https://github.com/res260/cfss
30+
cfss: "CFSS:0.3/TS:B/E:M/HSFC:N=4-7"
2931
tags:
3032
# Name of the discourse trigger for this flag. If a discourse post in the posts/ directory has this trigger, it will be posted when this flag is submitted.
3133
# This value can also be used to reference flags in Ansible playbooks. See the "Load Flags" task in deploy.yaml.

ctf/validators.py

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,69 @@ def validate(self, track_name: str) -> list[ValidationError]:
449449
return errors
450450

451451

452+
class CFSSStringValidator(Validator):
453+
"""Validate the CFSS string of each flag in the track.yaml."""
454+
455+
CFSS_VALUE_REGEX = re.compile(
456+
r"^CFSS:[0-9]\.[0-9][0-9]?/TS:[LBIA]/E:[LMH]/HSFC:[NY]=([0-9][0-9]?-[0-9][0-9]?)$"
457+
)
458+
459+
def validate(self, track_name: str) -> list[ValidationError]:
460+
errors: list[ValidationError] = []
461+
462+
track_yaml = parse_track_yaml(track_name=track_name)
463+
for flag in track_yaml["flags"]:
464+
if "cfss" not in flag:
465+
errors.append(
466+
ValidationError(
467+
error_name="CFSS string not found",
468+
error_description="CFSS string was not present in the track.yaml.",
469+
track_name=track_name,
470+
details={
471+
"CFSS string": "Not found",
472+
"Flag value": str(flag.get("value")),
473+
},
474+
)
475+
)
476+
continue
477+
478+
cfss: str = flag.get("cfss")
479+
value: int = flag.get("value")
480+
481+
# Should never happen since schemas/track.yaml.json is validated first.
482+
if not (m := self.CFSS_VALUE_REGEX.match(cfss)):
483+
errors.append(
484+
ValidationError(
485+
error_name="CFSS string did not match REGEX",
486+
error_description='CFSS string did not match "^CFSS:[0-9]\\.[0-9][0-9]?/TS:[LBIA]/E:[LMH]/HSFC:[NY]=([0-9][0-9]?-[0-9][0-9]?)$".',
487+
track_name=track_name,
488+
details={"CFSS string": cfss, "Flag value": str(value)},
489+
)
490+
)
491+
continue
492+
493+
low, high = m.group(1).split("-")
494+
if value < int(low) or value > int(high):
495+
errors.append(
496+
ValidationError(
497+
error_name="Flag value not in CFSS range",
498+
error_description="Flag value did not correspond to CFSS string's value.",
499+
track_name=track_name,
500+
details={"CFSS string": cfss, "Flag value": str(value)},
501+
)
502+
)
503+
continue
504+
return errors
505+
506+
452507
validators_list = [
508+
CFSSStringValidator,
509+
DiscourseFileNamesValidator,
510+
DiscoursePostsAskGodTagValidator,
453511
FilesValidator,
454-
FlagsValidator,
455512
FireworksAskGodTagValidator,
456-
DiscoursePostsAskGodTagValidator,
513+
FlagsValidator,
514+
OrphanServicesValidator,
457515
PlaceholderValuesValidator,
458-
DiscourseFileNamesValidator,
459516
ServicesValidator,
460-
OrphanServicesValidator,
461517
]

0 commit comments

Comments
 (0)