Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre event check only checking start of flag #283

Merged
merged 2 commits into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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