fix: masked secret shape detection

This commit is contained in:
Sabiha Khan 2026-06-29 17:27:04 +05:30
parent d9800fddd6
commit d383729f50
2 changed files with 34 additions and 2 deletions

View file

@ -28,7 +28,19 @@ def contains_masked_key(value: str | list[str] | None) -> bool:
if value is None:
return False
keys = value if isinstance(value, list) else [value]
return any(MASK_MARKER in k for k in keys)
return any(MASK_MARKER in k or _matches_mask_shape(k) for k in keys)
def _matches_mask_shape(key: str) -> bool:
"""Return True when *key* has the exact shape produced by mask_key()."""
if not key:
return False
if len(key) <= VISIBLE_CHARS:
return key == MASK_CHAR * len(key)
masked_prefix_length = len(key) - VISIBLE_CHARS
return key[:masked_prefix_length] == MASK_CHAR * masked_prefix_length
def check_for_masked_keys(config: "EffectiveAIModelConfiguration") -> None: