Skip to content

Commit

Permalink
Fix pre event check only checking start of flag (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAda committed Sep 26, 2024
1 parent 5b29f30 commit ea385ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugins/flag/plaintext.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self_check(self):
return ["property 'flag' must be set!"]

set_flag = self.challenge.flag_metadata["flag"]
if not set_flag.startswith(config.get("flag_prefix")):
if not set_flag.startswith(config.get("flag_prefix")) or not set_flag.endswith("}"):
return ["flag does not conform to event flag format!"]

return []
20 changes: 20 additions & 0 deletions src/plugins/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ def test_valid_flag(self):
def test_invalid_flag(self):
self.assertFalse(self.plugin.check("ractf{b}"))

def test_self_check_valid_flag(self):
self.challenge.flag_metadata["flag"] = "ractf{a}"
PlaintextFlagPlugin(self.challenge)
self.assertEqual(len(self.plugin.self_check()), 0)

def test_self_check_no_flag(self):
self.challenge.flag_metadata["flag"] = ""
PlaintextFlagPlugin(self.challenge)
self.assertEqual(len(self.plugin.self_check()), 1)

def test_self_check_no_flag_prefix(self):
self.challenge.flag_metadata["flag"] = "a}"
PlaintextFlagPlugin(self.challenge)
self.assertEqual(len(self.plugin.self_check()), 1)

def test_self_check_no_flag_suffix(self):
self.challenge.flag_metadata["flag"] = "ractf{a"
PlaintextFlagPlugin(self.challenge)
self.assertEqual(len(self.plugin.self_check()), 1)


class RegexFlagPluginTestCase(APITestCase):
def setUp(self):
Expand Down

0 comments on commit ea385ab

Please sign in to comment.