o
    iy                     @   s   d dl mZ d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ G dd deZdddddddZdadefddZdS )    )IAST)IAST_SPAN_TAGS)is_iast_request_enabled)
iast_error)%iast_propagation_sink_point_debug_log)_set_metric_iast_executed_sink)"_set_metric_iast_instrumented_sink)increment_iast_span_metric)VulnerabilityType)
get_ranges)	VULN_SSRF)VulnerabilityBase)ArgumentError)get_argument_valuec                   @   s   e Zd ZeZejZdS )SSRFN)__name__
__module____qualname__r   vulnerability_typer
   r   secure_mark r   r   Y/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/appsec/_iast/taint_sinks/ssrf.pyr      s    
r   )r   url)   r   )zrequests.apizurllib.requesturllib3zhttp.clientzurllib3._request_methods
webbrowserF	func_namec              
      sX  t stt da t|d\}}|du r t| d|  d dS z|r%|nd}tt||||}W n tyE   td| d|   Y dS w |rt	|t
jrt rz<t rt|rd}|d t|}	 d	krwt fd
d|	D rwd}|rtj|d ttj ttjtj W dS  ty }
 ztd|
 W Y d}
~
dS d}
~
ww dS dS dS )a  
    Check and report potential SSRF (Server-Side Request Forgery) vulnerabilities in function calls.

    This function analyzes calls to URL-handling functions to detect potential SSRF vulnerabilities.
    It checks if the URL argument is tainted (user-controlled) and reports it if conditions are met.
    URL fragments (parts after #) are handled specially - if all tainted parts are in the fragment,
    no vulnerability is reported.
    T)NNN.z2 not found in list of functions supported for SSRF zHFailed to get URL argument from _FUNC_TO_URL_ARGUMENT dict for function #c                 3   s    | ]}|j  kV  qd S )N)start).0rfragment_startr   r   	<genexpr>I   s    z$_iast_report_ssrf.<locals>.<genexpr>F)evidence_valuez3propagation::sink_point::Error in _iast_report_ssrf)#IS_REPORTED_INTRUMENTED_SINK_METRICr   r   _FUNC_TO_URL_ARGUMENTgetr   r   listr   
isinstancer   
TEXT_TYPESr   r   	has_quotais_tainted_pyobjectfindr   allreportr   r   r	   r   TELEMETRY_EXECUTED_SINK	Exceptionr   )r   module_nameargskwargsarg_pos
kwarg_namekwreport_ssrfvalid_to_reporttaint_rangeser   r$   r   _iast_report_ssrf#   sL   


r?   N)ddtrace.appsec._constantsr   r   /ddtrace.appsec._iast._iast_request_context_baser   ddtrace.appsec._iast._logsr   r   ddtrace.appsec._iast._metricsr   r   "ddtrace.appsec._iast._span_metricsr	   $ddtrace.appsec._iast._taint_trackingr
   r   ddtrace.appsec._iast.constantsr   &ddtrace.appsec._iast.taint_sinks._baser   ddtrace.internal.utilsr   r   r   r)   r(   strr?   r   r   r   r   <module>   s0    
