1422 block imports without db folder (#1424)

* Don't allow backups to be imported if they do not have a `db` folder
* Closes #1422
This commit is contained in:
Kevin Chung
2020-05-20 15:52:09 -04:00
committed by GitHub
parent 5618f0d04c
commit ba887e8952

View File

@@ -96,6 +96,14 @@ def import_ctf(backup, erase=True):
if info.file_size > max_content_length:
raise zipfile.LargeZipFile
# Get list of directories in zipfile
member_dirs = [os.path.split(m)[0] for m in members if "/" in m]
if "db" not in member_dirs:
raise Exception(
'CTFd couldn\'t find the "db" folder in this backup. '
"The backup may be malformed or corrupted and the import process cannot continue."
)
try:
alembic_version = json.loads(backup.open("db/alembic_version.json").read())
alembic_version = alembic_version["results"][0]["version_num"]