From e7f4e77af0912dd2419b5e94ca2aeae9f7304772 Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Fri, 24 Apr 2026 13:00:33 -0700 Subject: [PATCH] Bound _get_masked_values recursion depth Add _depth/_max_depth guards (default 20) so the nested dict masking cannot run away, and allowlist the function in the recursive_detector CI check alongside the other bounded recursive helpers. --- litellm/litellm_core_utils/litellm_logging.py | 6 ++++++ tests/code_coverage_tests/recursive_detector.py | 1 + 2 files changed, 7 insertions(+) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 70da405eef..fe5b75359b 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -3517,6 +3517,8 @@ def _get_masked_values( mask_all_values: bool = False, unmasked_length: int = 4, number_of_asterisks: Optional[int] = 4, + _depth: int = 0, + _max_depth: int = 20, ) -> dict: """ Internal debugging helper function @@ -3540,12 +3542,16 @@ def _get_masked_values( def _mask_value(v: Any) -> Any: if isinstance(v, dict): + if _depth >= _max_depth: + return v return _get_masked_values( v, ignore_sensitive_values=ignore_sensitive_values, mask_all_values=mask_all_values, unmasked_length=unmasked_length, number_of_asterisks=number_of_asterisks, + _depth=_depth + 1, + _max_depth=_max_depth, ) if not isinstance(v, str): return v diff --git a/tests/code_coverage_tests/recursive_detector.py b/tests/code_coverage_tests/recursive_detector.py index 99b5125b19..fc9c99f6af 100644 --- a/tests/code_coverage_tests/recursive_detector.py +++ b/tests/code_coverage_tests/recursive_detector.py @@ -45,6 +45,7 @@ IGNORE_FUNCTIONS = [ "_convert_to_json_serializable_dict", # max depth set (default 20) and circular reference protection to prevent infinite recursion. "dict", # max depth set. _LiteLLMParamsDictView.dict() calls builtin dict(), not itself. "_read_image_bytes", # max depth set. + "_get_masked_values", # max depth set (default 20) to prevent infinite recursion while masking nested sensitive config dicts. ]