Ë
    §‘ˆj!
  ã                   ó–   — d Z ddlZddlZddlZddlmZ ddlmZ  ej                  e	«      Z
dZ G d„ de«      Zded	efd
„Zded	efd„Zy)a  Rejects user-supplied URLs that point inside the network.

Any endpoint that fetches a URL a user chose is an SSRF sink: pointed at cloud
instance metadata it leaks credentials, pointed at an RFC1918 address it reaches
services that were never meant to be public.
é    N)ÚAny)Úurlparse)Úhttpsc                   ó   — e Zd ZdZy)ÚUnsafeUrlErrorz:The URL points somewhere this service must not fetch from.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    ú6/var/www/html/strategist-ai/app/services/infra/ssrf.pyr   r      s   „ ÚDr   r   ÚhostÚreturnc                 ó`   — t        j                  | d «      D �cg c]
  }|d   d   ‘Œ c}S c c}w )Né   r   )ÚsocketÚgetaddrinfo)r   Úinfos     r   Ú_resolver      s+   € Ü#)×#5Ñ#5°d¸DÓ#AÖB˜4ˆD�‰G�A‹JÒBÐBùÒBs   ™+Úurlc                 óf  — | rt        | t        «      st        d«      ‚	 t        | «      }|j                  }|j                  t        vrt        d|j                  ›d�«      ‚|st        d«      ‚	 t        |«      }|D ]n  }t        j                  |«      }|j                  s=|j                  s1|j                  s%|j                   s|j"                  s|j$                  sŒat        d|›d�«      ‚ | S # t
        $ r}t        d«      |‚d }~ww xY w# t        t        f$ r}t        d|›d�«      |‚d }~ww xY w)	Nzurl must be a non-empty stringzurl could not be parsedzscheme z is not allowedzurl has no hostzhost z does not resolvez! resolves to a non-public address)Ú
isinstanceÚstrr   r   ÚhostnameÚ
ValueErrorÚschemeÚALLOWED_SCHEMESr   ÚOSErrorÚUnicodeErrorÚ	ipaddressÚ
ip_addressÚ
is_privateÚis_loopbackÚis_link_localÚis_reservedÚis_multicastÚis_unspecified)r   Úparsedr   ÚexÚ	addressesÚrawÚips          r   Úassert_safe_urlr.      s?  € Ù”j ¤cÔ*ÜÐ=Ó>Ð>ð
@Ü˜#“ˆØ—?‘?ˆð ‡}�}œOÑ+Ü˜w v§}¡}Ð&7°ÐGÓHÐHÙÜÐ.Ó/Ð/ðLÜ˜XÓ&ˆ	ð ò 	Gˆô ×!Ñ! #Ó&ˆØ�MŠM˜RŸ^š^¨r×/?Ò/?Ø—>’> R§_¢_¸×8IÓ8Iô !Ø˜�|Ð#DÐEóGð Gð	Gð €Jøô7 ò @ÜÐ6Ó7¸RÐ?ûð@ûô ”\Ð"ò Lô ˜u X LÐ0AÐBÓCÈÐKûð	Lús/   ŸC/ Á/D Ã/	D	Ã8DÄD	ÄD0ÄD+Ä+D0)r   r!   Úloggingr   Útypingr   Úurllib.parser   Ú	getLoggerr   Úloggerr   Ú	Exceptionr   r   Úlistr   r.   r   r   r   ú<module>r6      sk   ðñó Û Û Ý Ý !à	ˆ×	Ñ	˜8Ó	$€ð
 €ôE�Yô EðC�3ð C˜4ó Cð%˜ð % ô %r   