Django の
この--deploy
と
このチェックを
参考
- Django 管理コマンド manage.py まとめ
- System check framework | Django documentation | Django
- [Django 1.8で
追加されたSecurityMiddlewareに ついて - 偏った 言語信者の 垂れ流し] (https://tokibito.hatenablog.com/entry/20150624/1435073520)
前提
以下の
OS
cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core)
Python Version
python3.6 -V Python 3.6.4
Django Version
python3.6 -m pip list Django 1.10.8
check コマンドの 結果
コマンド
python3.6 manage.py check --deploy
実行結果
以下、警告が 出力されました。 計 8 つ 出力されています。 System check identified some issues: WARNINGS: ?: (security.W004) 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. ?: (security.W006) Your 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. ?: (security.W007) Your SECURE_BROWSER_XSS_FILTER setting is not set to True, so your pages will not be served with an 'x-xss-protection: 1; mode=block' header. You should consider enabling this header to activate the browser's XSS filtering and help prevent XSS attacks. ?: (security.W008) 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. ?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions. ?: (security.W016) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE, but you have not set CSRF_COOKIE_SECURE to True. Using a secure-only CSRF cookie makes it more difficult for network traffic sniffers to steal the CSRF token. ?: (security.W017) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE, but you have not set CSRF_COOKIE_HTTPONLY to True. Using an HttpOnly CSRF cookie makes it more difficult for cross-site scripting attacks to steal the CSRF token. ?: (security.W019) You have 'django.middleware.clickjacking.XFrameOptionsMiddleware' in your MIDDLEWARE, but X_FRAME_OPTIONS is not set to 'DENY'. The default is 'SAMEORIGIN', but unless there is a good reason for your site to serve other parts of itself in a frame, you should change it to 'DENY'.
警告への 対処
security.W004
SECURE_HSTS_SECONDS
が未設定の 旨を 示す 警告に なります。 これを 設定すると、 strict-transport-security
が付与されます。
関連項目に、SECURE_HSTS_INCLUDE_SUBDOMAINS
があり、 これも 合わせて 設定します。 # security.W004 SECURE_HSTS_SECONDS = 31536000 SECURE_HSTS_INCLUDE_SUBDOMAINS = True
security.W006
SECURE_CONTENT_TYPE_NOSNIFF
が未設定の 旨を 示す 警告に なります。 True に すると、 x-content-type-options: nosniff
が付与されます。 # security.W006 SECURE_CONTENT_TYPE_NOSNIFF = True
security.W007
SECURE_BROWSER_XSS_FILTER
が未設定の 旨を 示す 警告に なります。 True に すると、 x-xss-protection: 1; mode=block
が付与されます。 # security.W007 SECURE_BROWSER_XSS_FILTER = True
security.W008
SECURE_SSL_REDIRECT
が未設定の 旨を 示す 警告に なります。 True に すると、 HTTP通信の 場合、 強制的に HTTPSに リダイレクトされます。 # security.W008 SECURE_SSL_REDIRECT = True
security.W012
SESSION_COOKIE_SECURE
が未設定の 旨を 示す 警告に なります。 True に すると、 Session Cookie の secure 属性が True に なります。
session_id という Cookie の secure 属性が 切り 替わります。 # security.W012 SESSION_COOKIE_SECURE = True
security.W016、
security.W017
django.middleware.csrf.CsrfViewMiddleware
で付与される CRSF token の Cookie に Secure 属性が 付与されていない、 Httponly 属性が ついていないと いう 警告に なります。 CSRF_COOKIE_SECURE
、CSRF_COOKIE_HTTPONLY
の設定を True に します。 # security.W016、security.W017 CSRF_COOKIE_SECURE = True CSRF_COOKIE_HTTPONLY = True
security.W019
django.middleware.clickjacking.XFrameOptionsMiddleware
の、X_FRAME_OPTIONS
の値が 未設定の 旨を 示す 警告に なります。
デフォルト値は、SAMEORIGIN
で、DENY
でも問題ないため、 DENY
を設定します。 # security.W019 X_FRAME_OPTIONS = 'DENY'
上記の
HTTP サーバ側で
以上です。
コメント