
    ہh                         d dl Z d dlZd dlmZmZ d dlmZ d dlmZ  ej                  ej                  d        ej                  e      Z G d de      Zy)	    N)DictAny)CountermeasurePlugin)sanitize_for_logz4%(asctime)s - %(name)s - %(levelname)s - %(message)s)levelformatc                   @    e Zd ZdZdeeef   deeef   fdZdefdZy)InjectContentCountermeasureuF   
    在响应内容中注入HTML或JS代码的反制动作实现
    contextreturnc                 "   |j                  di       }|j                  dd      }|j                  dd      }|st        j                  d       dddS t        |d	d
       }t        |      }t        j	                  d| d| d       dd||ddS )u>  
        执行内容注入动作。
        注意：这个插件的设计是让规则引擎在需要时调用它，
        并将注入的代码通过 context 传给它。
        实际的注入逻辑需要在 HTTP 服务器层面实现，
        这个 execute 方法主要用于记录和返回结果。
        configlocationbefore_body_endcontent zNo content specified to inject.F)successmessageN   zPrepared to inject content at 'z': z...TzContent injection prepared.)r   r   )r   r   inject_info)getloggerwarningr   info)selfr   r   inject_locationcontent_to_injectpreviewsafe_locations          AE:\workrun\ive\./countermeasures\inject_content\countermeasure.pyexecutez#InjectContentCountermeasure.execute   s     Xr* **Z1BC"JJy"5 NN<=$1RSS"#4Tc#:;(95m_CyPSTU
 4+,
 	
    c                      y)NzDPrepares HTML/JS content to be injected into the HTTP response body. )r   s    r    get_descriptionz+InjectContentCountermeasure.get_description/   s    Ur"   N)	__name__
__module____qualname____doc__r   strr   r!   r%   r$   r"   r    r
   r
      s8    
tCH~ 
$sCx. 
>V Vr"   r
   )reloggingtypingr   r   pluginsr   core.log_utilsr   basicConfigINFO	getLoggerr&   r   r
   r$   r"   r    <module>r3      sN    	   ( +   ',,/e f			8	$%V"6 %Vr"   