From 79b1ad9a4fd0727c5050e8fa235e779d63c9f059 Mon Sep 17 00:00:00 2001 From: Itamar Gafni Date: Tue, 17 Mar 2026 04:15:58 +0200 Subject: [PATCH] fix(web): don't cache empty VM tags when machines table is transiently empty The CAPE service clears the machines table on startup (clean_machines) and re-adds them from config. If it crashes before re-adding, the table is temporarily empty. Gunicorn workers that handle a tagged submission during this window permanently cache an empty tag list, causing all subsequent tagged submissions to be rejected with "incorrect tag(s)". Only cache the result when machines actually exist in the DB. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/cuckoo/common/web_utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/cuckoo/common/web_utils.py b/lib/cuckoo/common/web_utils.py index 077056c46eb..b5faa3d1e48 100644 --- a/lib/cuckoo/common/web_utils.py +++ b/lib/cuckoo/common/web_utils.py @@ -230,7 +230,7 @@ def load_vms_tags(force: bool = False): global _all_vms_tags with _load_vms_tags_lock: if _all_vms_tags is not None and not force: - return _all_vms_tags + return _all_vms_tags or [] all_tags = [] if HAVE_DIST and dist_conf.distributed.enabled: try: @@ -242,11 +242,13 @@ def load_vms_tags(force: bool = False): except Exception as e: print(e) - for machine in Database().list_machines(include_reserved=True): + machines = Database().list_machines(include_reserved=True) + for machine in machines: all_tags += [tag.name for tag in machine.tags if tag not in all_tags] - _all_vms_tags = list(sorted(set(all_tags))) - return _all_vms_tags + if machines: + _all_vms_tags = list(sorted(set(all_tags))) + return _all_vms_tags or [] def top_asn(date_since: datetime = False, results_limit: int = 20) -> dict: