CTFd / ctfcli

ctfcli is a tool to manage Capture The Flag events and challenges
https://ctfd.io/
Apache License 2.0
174 stars 74 forks source link

File key not respecting null keys #163

Open jimender2 opened 1 week ago

jimender2 commented 1 week ago

Inside of most of the keys, it is optional to have values.

https://github.com/CTFd/ctfcli/blob/d8e08daedd6d22159f5978e1619b9d7073aa07f8/ctfcli/core/challenge.py#L583

For files, it is not optional and fails if you have no files under your key. Removing the key fixes the issue but this should be either documented in the spec better or fixed (preferred I think). Might be as simple as a better check?

https://github.com/CTFd/ctfcli/blob/d8e08daedd6d22159f5978e1619b9d7073aa07f8/ctfcli/core/challenge.py#L589

Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.11.10/x64/bin/ctf", line 8, in sys.exit(main()) ^^^^^^ File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/ctfcli/main.py", line 136, in main ret = fire.Fire(COMMANDS["cli"], serialize=lambda r: None if isinstance(r, int) else r) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/fire/core.py", line 141, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/fire/core.py", line 475, in _Fire component, remaining_args = _CallAndUpdateTrace( ^^^^^^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace component = fn(*varargs, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/ctfcli/cli/challenges.py", line 617, in install challenge_instance.sync(ignore=ignore) File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/ctfcli/core/challenge.py", line 589, in sync local_files = {f.split("/")[-1]: f for f in self.get("files", [])} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'NoneType' object is not iterable