o
    h                     @   sf   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d eeZG dd deZdS )	    N)DictAny)CountermeasurePlugin)sanitize_for_logz4%(asctime)s - %(name)s - %(levelname)s - %(message)s)levelformatc                   @   s@   e Zd ZdZdeeef deeef fddZdefddZdS )	InjectContentCountermeasureuF   
    在响应内容中注入HTML或JS代码的反制动作实现
    contextreturnc                 C   s~   | di }| dd}| dd}|std dddS t|d	d
 }t|}t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   Zinject_locationcontent_to_injectZpreviewZsafe_location r   </root/ive/./countermeasures/inject_content/countermeasure.pyexecute   s   

z#InjectContentCountermeasure.executec                 C   s   dS )NzDPrepares HTML/JS content to be injected into the HTTP response body.r   )r   r   r   r   get_description/   s   z+InjectContentCountermeasure.get_descriptionN)	__name__
__module____qualname____doc__r   strr   r   r   r   r   r   r   r      s    "r   )reloggingtypingr   r   pluginsr   core.log_utilsr   basicConfigINFO	getLoggerr   r   r   r   r   r   r   <module>   s    
