Ë
    tPêj
  ã                   ó@   — d Z ddlZddlmZ dededefd„Zdedefd	„Zy)
zñ
Safe filesystem path construction for user-controlled inputs.

Use safe_join() instead of os.path.join() whenever a path component
comes from user input (request parameters, uploaded filenames, etc.)
to prevent directory traversal attacks.
é    N)ÚFinalÚbase_dirÚpartsÚreturnc                 óZ  — |D ]  }d|v sŒt        d«      ‚ t        j                  j                  | «      }t        j                  j                  t        j                  j                  |g|¢­Ž «      }|j                  |t        j                  z   «      s||k(  st        d|›d|›�«      ‚|S )aÜ  
    Join path components and verify the result stays within base_dir.

    Resolves symlinks and '..' sequences, then checks the final path
    is a descendant of base_dir. Raises ValueError if traversal is
    detected.

    Args:
        base_dir: The trusted base directory.
        *parts: User-controlled path components to append.

    Returns:
        The resolved absolute path as a string.

    Raises:
        ValueError: If the resolved path escapes base_dir.
    ú zPath contains null bytezPath z escapes base directory )Ú
ValueErrorÚosÚpathÚrealpathÚjoinÚ
startswithÚsep)r   r   ÚpartÚbaseÚresolveds        új/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/common_utils/path_utils.pyÚ	safe_joinr      s�   € ð$ ò 8ˆØ�TŠ>ÜÐ6Ó7Ð7ð8ô —'‘'×"Ñ" 8Ó,€DÜ—g‘g×&Ñ&¤r§w¡w§|¡|°DÐ'A¸5Ò'AÓB€HØ×Ñ ¤r§v¡v¡Ô.°(¸dÒ2BÜ˜5  Ð,DÀTÀHÐMÓNÐNØ€Oó    Úfilenamec                 ó�   — d| v rt        d«      ‚| j                  dd«      j                  dd«      d   }|r|dv rt        d«      ‚|S )	aÛ  
    Extract a safe filename from a user-supplied path.

    Strips all directory components (both Unix and Windows separators),
    returning only the final name. Use this for uploaded file names
    before writing to disk.

    Args:
        filename: User-supplied filename (may contain path separators).

    Returns:
        The basename only, with no directory components.

    Raises:
        ValueError: If the resulting filename is empty or contains null bytes.
    r   zFilename contains null byteú\ú/é   éÿÿÿÿ)ú.z..zEmpty or unsafe filename)r	   ÚreplaceÚrsplit)r   Únames     r   Úsafe_filenamer    )   sW   € ð" �ÑÜÐ6Ó7Ð7à×"Ñ" 4¨Ó-×4Ñ4°S¸!Ó<¸RÑ@€DÙ�4˜;Ñ&ÜÐ3Ó4Ð4Ø€Kr   )Ú__doc__r
   Útypingr   Ústrr   r    © r   r   ú<module>r%      s?   ðñó 
Ý ð˜ð  Sð ¨Só ð8˜Cð  Cô r   