From 2cf521e57e2f17241cd2a0e2cd84233eb807692b Mon Sep 17 00:00:00 2001 From: zhayujie Date: Sun, 5 Jul 2026 12:35:24 +0800 Subject: [PATCH] fix: exception handling in config eval --- config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index d7bf650b..51f699ff 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,6 @@ # encoding:utf-8 +import ast import copy import json import logging @@ -427,9 +428,12 @@ def load_config(): # ast.literal_eval only parses Python literals (strings, numbers, # tuples, lists, dicts, booleans, None) and CANNOT execute # arbitrary code, preventing environment-variable injection. - import ast config[name] = ast.literal_eval(value) - except (ValueError, SyntaxError): + except Exception: + # literal_eval can raise ValueError/SyntaxError for non-literal + # strings, but also TypeError/RecursionError on malformed input + # (e.g. unhashable dict keys); catch broadly to avoid crashing + # startup, and fall back to treating the value as a plain string. if value.lower() == "false": config[name] = False elif value.lower() == "true":