3
v^                 @   s  d dl mZ ddlmZmZmZmZ dddddd	d
dhZdZdZ	edddZ
edddZedddZedddZedddZedddZedee	d ddZedddZed d!dZed"d#dZed$d%dZed&d'dZed(d)jd*jeed+d,Zd-d. Zd/d0 Zeejd1d2d3d4 Zeejd1d2d5d6 Zeejd1d2d7d8 Zeejd1d2d9d: Z eejd1d2d;d< Z!eejd1d2d=d> Z"eejd1d2d?d@ Z#eejd1d2dAdB Z$eejd1d2dCdD Z%eejd1d2dEdF Z&eejd1d2dGdH Z'eejd1d2dIdJ Z(dKS )L    )settings   )ErrorTagsWarningregisterzno-referrerzno-referrer-when-downgradeoriginzorigin-when-cross-originzsame-originzstrict-originzstrict-origin-when-cross-originz
unsafe-url2      zYou do not have 'django.middleware.security.SecurityMiddleware' in your MIDDLEWARE so the SECURE_HSTS_SECONDS, SECURE_CONTENT_TYPE_NOSNIFF, SECURE_BROWSER_XSS_FILTER, SECURE_REFERRER_POLICY, and SECURE_SSL_REDIRECT settings will have no effect.zsecurity.W001)ida3  You do not have 'django.middleware.clickjacking.XFrameOptionsMiddleware' in your MIDDLEWARE, so your pages will not be served with an 'x-frame-options' header. Unless there is a good reason for your site to be served in a frame, you should consider enabling this header to help prevent clickjacking attacks.zsecurity.W002a,  You have not set a value for the SECURE_HSTS_SECONDS setting. If your entire site is served only over SSL, you may want to consider setting a value and enabling HTTP Strict Transport Security. Be sure to read the documentation first; enabling HSTS carelessly can cause serious, irreversible problems.zsecurity.W004a  You have not set the SECURE_HSTS_INCLUDE_SUBDOMAINS setting to True. Without this, your site is potentially vulnerable to attack via an insecure connection to a subdomain. Only set this to True if you are certain that all subdomains of your domain should be served exclusively via SSL.zsecurity.W005zYour SECURE_CONTENT_TYPE_NOSNIFF setting is not set to True, so your pages will not be served with an 'X-Content-Type-Options: nosniff' header. You should consider enabling this header to prevent the browser from identifying content types incorrectly.zsecurity.W006a  Your SECURE_SSL_REDIRECT setting is not set to True. Unless your site should be available over both SSL and non-SSL connections, you may want to either set this setting True or configure a load balancer or reverse-proxy server to redirect all connections to HTTPS.zsecurity.W008zYour SECRET_KEY has less than %(min_length)s characters or less than %(min_unique_chars)s unique characters. Please generate a long and random SECRET_KEY, otherwise many of Django's security-critical features will be vulnerable to attack.)Z
min_lengthZmin_unique_charszsecurity.W009z4You should not have DEBUG set to True in deployment.zsecurity.W018zYou have 'django.middleware.clickjacking.XFrameOptionsMiddleware' in your MIDDLEWARE, but X_FRAME_OPTIONS is not set to 'DENY'. Unless there is a good reason for your site to serve other parts of itself in a frame, you should change it to 'DENY'.zsecurity.W019z.ALLOWED_HOSTS must not be empty in deployment.zsecurity.W020zYou have not set the SECURE_HSTS_PRELOAD setting to True. Without this, your site cannot be submitted to the browser preload list.zsecurity.W021zYou have not set the SECURE_REFERRER_POLICY setting. Without this, your site will not send a Referrer-Policy header. You should consider enabling this header to protect user privacy.zsecurity.W022zDYou have set the SECURE_REFERRER_POLICY setting to an invalid value.zValid values are: {}.z, zsecurity.E023)hintr   c               C   s
   dt jkS )Nz-django.middleware.security.SecurityMiddleware)r   
MIDDLEWARE r   r   D/usr/lib/python3.6/site-packages/django/core/checks/security/base.py_security_middlewarew   s    r   c               C   s
   dt jkS )Nz6django.middleware.clickjacking.XFrameOptionsMiddleware)r   r   r   r   r   r   _xframe_middleware{   s    r   T)deployc             K   s   t  }|rg S tgS )N)r   W001)app_configskwargspassed_checkr   r   r   check_security_middleware   s    r   c             K   s   t  }|rg S tgS )N)r   W002)r   r   r   r   r   r   check_xframe_options_middleware   s    r   c             K   s   t   ptj}|rg S tgS )N)r   r   SECURE_HSTS_SECONDSW004)r   r   r   r   r   r   	check_sts   s    r   c             K   s(   t   ptj ptjdk}|r"g S tgS )NT)r   r   r   SECURE_HSTS_INCLUDE_SUBDOMAINSW005)r   r   r   r   r   r   check_sts_include_subdomains   s    
r   c             K   s(   t   ptj ptjdk}|r"g S tgS )NT)r   r   r   SECURE_HSTS_PRELOADW021)r   r   r   r   r   r   check_sts_preload   s    
r"   c             K   s    t   ptjdk}|rg S tgS )NT)r   r   SECURE_CONTENT_TYPE_NOSNIFFW006)r   r   r   r   r   r   check_content_type_nosniff   s    
r%   c             K   s    t   ptjdk}|rg S tgS )NT)r   r   SECURE_SSL_REDIRECTW008)r   r   r   r   r   r   check_ssl_redirect   s    
r(   c             K   s:   t tdd o*tttjtko*ttjtk}|r4g S tgS )N
SECRET_KEY)getattrr   lensetr)    SECRET_KEY_MIN_UNIQUE_CHARACTERSSECRET_KEY_MIN_LENGTHW009)r   r   r   r   r   r   check_secret_key   s    r0   c             K   s   t j }|rg S tgS )N)r   DEBUGW018)r   r   r   r   r   r   check_debug   s    r3   c             K   s    t   ptjdk}|rg S tgS )NDENY)r   r   X_FRAME_OPTIONSW019)r   r   r   r   r   r   check_xframe_deny   s    
r7   c             K   s   t jr
g S tgS )N)r   ALLOWED_HOSTSW020)r   r   r   r   r   check_allowed_hosts   s    r:   c             K   sV   t  rRtjd krtgS ttjtr:dd tjjdD }n
ttj}|tksRt	gS g S )Nc             S   s   h | ]}|j  qS r   )strip).0vr   r   r   	<setcomp>   s    z(check_referrer_policy.<locals>.<setcomp>,)
r   r   SECURE_REFERRER_POLICYW022
isinstancestrsplitr,   REFERRER_POLICY_VALUESE023)r   r   valuesr   r   r   check_referrer_policy   s    

rH   N))django.confr    r   r   r   r   rE   r.   r-   r   r   r   r   r$   r'   r/   r2   r6   r9   r!   rA   formatjoinsortedrF   r   r   securityr   r   r   r   r"   r%   r(   r0   r3   r7   r:   rH   r   r   r   r   <module>   s|   

		
	