
    [i                    ,    d Z ddlmZ ddlZddlZddZy)a^  Shared path security utilities for preventing path traversal and SSRF attacks.

This module provides a centralized implementation for path validation that is
used by multiple parts of the codebase. Having a single implementation ensures
consistent security checks and avoids divergent behavior between components.

Security Context
----------------
These checks are designed to run BEFORE any filesystem operations (like
``os.path.realpath()``) to prevent Windows from triggering SMB connections
to attacker-controlled servers when resolving UNC paths. This prevents
SSRF attacks and NTLM hash disclosure.
    )annotationsNc                d   d| v ry| j                  d      ryt        |       dk\  r| d   t        j                  v r	| d   dk(  ry| j                  d      ryt        j
                  j                  |       ry| j                  d	d
      }|j                  d
      D cg c]  }|s|	 }}d|v S c c}w )a  Return True if path contains UNC, absolute, drive, or traversal patterns.

    This function checks for dangerous path patterns that could lead to:
    - SSRF attacks via Windows UNC path resolution
    - NTLM hash disclosure via SMB connections
    - Path traversal outside intended directories
    - Path truncation via null bytes

    IMPORTANT: This check must run BEFORE any ``os.path.realpath()`` calls
    to prevent Windows from triggering SMB connections to attacker-controlled
    servers.

    Parameters
    ----------
    path : str
        The path string to validate.

    Returns
    -------
    bool
        True if the path contains unsafe patterns, False if it appears safe
        for further processing.

    Examples
    --------
    >>> is_unsafe_path_pattern("subdir/file.js")
    False
    >>> is_unsafe_path_pattern("\\\\server\\share")
    True
    >>> is_unsafe_path_pattern("../../../etc/passwd")
    True
    >>> is_unsafe_path_pattern("C:\\Windows\\system32")
    True
     T)z\\z//   r      :)\/r	   r
   z..)	
startswithlenstringascii_lettersospathisabsreplacesplit)r   
normalizedsegsegmentss       h/var/www/html/userprofiledev.eatanceapp.com/venv/lib/python3.12/site-packages/streamlit/path_security.pyis_unsafe_path_patternr   #   s    H ~ ~& 4yA~$q'V%9%99d1gn {# 
ww}}T dC(J)//4<44H<8 =s   B-#B-)r   strreturnbool)__doc__
__future__r   r   r   r        r   <module>r       s    # 	 ?r   