o
    ¨¼hç  ã                   @   s$   d dl Z ddededefdd„ZdS )	é    Né   ÚvalueÚ
max_lengthÚreturnc                 C   s^   | du rdS t | tƒst| ƒ} t dd| ¡} t dd| ¡ ¡ } t| ƒ|kr-| d|… d } | S )zôSanitize potentially attacker-controlled strings before logging.

    - Strip CR, LF, TAB and other ASCII control characters (0x00-0x1F, 0x7F)
    - Collapse whitespace runs to a single space
    - Truncate overly long inputs to max_length
    NÚ z[\x00-\x1F\x7F]ú z\s+u   â€¦)Ú
isinstanceÚstrÚreÚsubÚstripÚlen)r   r   © r   ú/root/ive/core/log_utils.pyÚsanitize_for_log   s   
r   )r   )r
   r	   Úintr   r   r   r   r   Ú<module>   s    