î
Ý^Q\à  ã               @   sV   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z Gd d „  d e ƒ Z d S)é    N)Úsettings)ÚHttpResponsePermanentRedirect)ÚMiddlewareMixinc               @   s7   e  Z d  Z d d d „ Z d d „  Z d d „  Z d S)ÚSecurityMiddlewareNc             C   sz   t  j |  _ t  j |  _ t  j |  _ t  j |  _ t  j	 |  _
 t  j |  _ t  j |  _ d d „  t  j Dƒ |  _ | |  _ d  S)Nc             S   s   g  |  ] } t  j | ƒ ‘ q S© )ÚreÚcompile)Ú.0Úrr   r   ú@/var/www/dbchiro/venv/build/Django/django/middleware/security.pyú
<listcomp>   s   	 z/SecurityMiddleware.__init__.<locals>.<listcomp>)r   ZSECURE_HSTS_SECONDSÚsts_secondsZSECURE_HSTS_INCLUDE_SUBDOMAINSÚsts_include_subdomainsZSECURE_HSTS_PRELOADÚsts_preloadZSECURE_CONTENT_TYPE_NOSNIFFÚcontent_type_nosniffZSECURE_BROWSER_XSS_FILTERÚ
xss_filterZSECURE_SSL_REDIRECTÚredirectZSECURE_SSL_HOSTÚredirect_hostZSECURE_REDIRECT_EXEMPTÚredirect_exemptÚget_response)Úselfr   r   r   r   Ú__init__	   s    zSecurityMiddleware.__init__c                s~   | j  j d ƒ ‰  |  j rz | j ƒ  rz t ‡  f d d †  |  j Dƒ ƒ rz |  j p] | j ƒ  } t d | | j	 ƒ  f ƒ Sd  S)Nú/c             3   s   |  ] } | j  ˆ  ƒ Vq d  S)N)Úsearch)r	   Úpattern)Úpathr   r   ú	<genexpr>   s   z5SecurityMiddleware.process_request.<locals>.<genexpr>zhttps://%s%s)
r   Úlstripr   Ú	is_secureÚanyr   r   Úget_hostr   Zget_full_path)r   ÚrequestÚhostr   )r   r   Úprocess_request   s    z"SecurityMiddleware.process_requestc             C   s¯   |  j  rg | j ƒ  rg d | k rg d |  j  } |  j rD | d } n  |  j rZ | d } n  | | d <n  |  j r‰ d | k r‰ d | d <n  |  j r« d | k r« d | d <n  | S)	Nzstrict-transport-securityz
max-age=%sz; includeSubDomainsz	; preloadzx-content-type-optionsZnosniffzx-xss-protectionz1; mode=block)r   r   r   r   r   r   )r   r!   ÚresponseZ
sts_headerr   r   r   Úprocess_response   s    		z#SecurityMiddleware.process_response)Ú__name__Ú
__module__Ú__qualname__r   r#   r%   r   r   r   r   r      s   
r   )r   Zdjango.confr   Zdjango.httpr   Zdjango.utils.deprecationr   r   r   r   r   r   Ú<module>   s   