mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-01 16:21:12 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user