過去に、OWASP ZAP
を
で
セキュリティ系の
の
こちらを
前提
以下の
OS
CentOS release 6.9 (Final)Python Version
Python 2.7.8Package (必要そうな
ものだけ 抜粋)
Django (1.10.6)
Mezzanine (4.2.3)
また、
警告出力は
検証の 内容
http-observatory-cli は
オプションなどはなく、 デフォルトで 検証を 実行 Mezzanine は、
公開画面 ドメイン指定での 検証と、 管理ログイン画面の 検証 を 行う
http-observatory-cli の インストールと 検証の 実行
インストール
pip
でインストールできます。 pip install httpobs-cli
検証の
実行 コマンドを 叩いて 検証を 実行します。 オプションhttpobs -v -z -x www.monotalk.xyz --------------------------------------------------- Score: 30 [D] Modifiers: [ 0] All cookies use the Secure flag and all session cookies use the HttpOnly flag [ 0] Content is not visible via cross-origin resource sharing (CORS) files or headers [ 0] Contribute.json isn't required on websites that don't belong to Mozilla [ 0] HTTP Public Key Pinning (HPKP) header not implemented [ 0] Referrer-Policy header not implemented [ 0] X-Content-Type-Options header set to "nosniff" [ 0] X-Frame-Options (XFO) header set to SAMEORIGIN or DENY [ 0] X-XSS-Protection header set to "1; mode=block" [ -5] Subresource Integrity (SRI) not implemented, but all external scripts are loaded over https [ -20] Does not redirect to an https site [ -20] HTTP Strict Transport Security (HSTS) header not implemented [ -25] Content Security Policy (CSP) header not implemented ---------------------------------------------------
-v -z -x
の意味は 以下の 通りです。 -z
問題のないチェック項目も 出力 -v
インジケーターの出力 -x
最近のスキャン結果に、 スキャン結果を 表示しない
警告の 内容と、 対処方法
Score は
Subresource Integrity (SRI) not implemented, but all external scripts are loaded over https
CDN 経由で
以下が、
google analyticsタグなどには、
付与できる
対処しませんでした。。
Does not redirect to an https site
HTTP から、
こちらは、
SECURE_SSL_REDIRECT = True
もちろんHTTPサーバー側でも
以下が、
自分の
https
に
<VirtualHost *:80> ServerName www.monotalk.xyz ServerAlias monotalk.xyz *.monotalk.xyz Redirect / https://www.monotalk.xyz/ </VirtualHost>
HTTP Strict Transport Security (HSTS) header not implemented
HSTSヘッダが
こちらも、SecurityMiddleware
の
以下をsettings.py
に
# 180日を設定 SECURE_HSTS_SECONDS = 15552000 # includeSubDomains を付与する SECURE_HSTS_INCLUDE_SUBDOMAINS = True # preload を付与する (django 1.11から追加) SECURE_HSTS_PRELOAD = True
以下、
[Django 1.8で
追加されたSecurityMiddlewareに ついて - 偏った 言語信者の 垂れ流し] (http://tokibito.hatenablog.com/entry/20150624/1435073520)
Content Security Policy (CSP) header not implemented
CSP ヘッダが
以下が
正直、
Report 機能のみ
Django だと、
Report を
と
django-csp の インストール
pip install
pip install django-csp ------------------------------------ Successfully installed django-csp-3.3 ------------------------------------
settings.py に
application を 追加 INSTALLED_APPS = ( "csp", ... )
MIDDLEWARE_CLASSES に
csp.middleware.CSPMiddleware
を追加 MIDDLEWARE_CLASSES = ( # ... 'csp.middleware.CSPMiddleware', # ... )
django-csp の
設定を 追加 CSP_REPORT_URI に django-csp-report の URLを、
CSP_REPORT_ONLY にTrue を 設定します。 ############################# # Django-CSP Settings ############################# CSP_DEFAULT_SRC = ("'self'") CSP_REPORT_URI = '/report/' CSP_REPORT_ONLY = True
django-csp-reports の インストール
pip install
pip install django-csp-reports ----------------------------------- Successfully installed django-csp-reports-1.1 -----------------------------------
settings.py に
application を 追加 INSTALLED_APPS = ( "cspreports", ... )
django-csp-reports の
設定を 追加
EMAIL で通知する 機能を OFF、
DBに書き込む 機能を OFFに 設定し、
LOGにのみ出力するようにします。 CSP_REPORTS_EMAIL_ADMINS = False CSP_REPORTS_SAVE = False
Loggerの
設定
handler にcsp_report_file を、
logger にCSP Reports を 追加します。
CSP Reports は、django-csp-reports の デフォルトの ロガー名です。
########################## # LOGGING SETTINGS ########################## # settings.py LOGGING = { 'version': 1, 'formatters': { 'verbose': { 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' }, 'simple': { 'format': '%(levelname)s %(message)s' }, }, 'handlers': { 'file': { 'class': 'logging.handlers.RotatingFileHandler', 'filename': '/var/log/your_app.log', 'maxBytes': 1024 * 1024 * 10, 'backupCount': 10, 'formatter': 'verbose', }, 'csp_report_file': { 'class': 'logging.handlers.RotatingFileHandler', 'filename': '/var/log/your_csp_report.log', 'maxBytes': 1024 * 1024 * 10, 'backupCount': 10, 'formatter': 'verbose', }, }, 'loggers': { 'django.request': { 'handlers': ['file'], 'level': 'INFO', 'propagate': False, }, 'django_crontab': { 'handlers': ['file'], 'level': 'INFO', 'propagate': False, }, 'CSP Reports': { 'handlers': ['csp_report_file'], 'level': 'INFO', 'propagate': False, } }, }
- urls.py に
django-csp-reports の url を 追加 urlpatterns += [ url("^", include("cspreports.urls")), ]
これで、
しばらく
WARNING 2017-04-17 02:40:06,206 utils 17040 140383643092736 Content Security Policy violation: { "csp-report": { "blocked-uri": "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js", "disposition": "report", "document-uri": "https://www.monotalk.xyz/", "effective-directive": "script-src", "original-policy": "default-src 'self'; report-uri /report/", "referrer": "", "status-code": 0, "violated-directive": "script-src" } }
[2] 後日、
Looger 設定の'%(message)s'
だけ
RDBなりに
http-observatory-cli で 再度、 検証の 実行
再度検証するには、-r
オプションを
コマンドを
付けないと、
httpobs -r -v -z -x www.monotalk.xyz ------------------------------------------------------------- Score: 70 [B] Modifiers: [ 0] All cookies use the Secure flag and all session cookies use the HttpOnly flag [ 0] Content is not visible via cross-origin resource sharing (CORS) files or headers [ 0] Contribute.json isn't required on websites that don't belong to Mozilla [ 0] HTTP Public Key Pinning (HPKP) header not implemented [ 0] HTTP Strict Transport Security (HSTS) header set to a minimum of six months (15768000) [ 0] Initial redirection is to https on same host, final destination is https [ 0] Referrer-Policy header not implemented [ 0] X-Content-Type-Options header set to "nosniff" [ 0] X-Frame-Options (XFO) header set to SAMEORIGIN or DENY [ 0] X-XSS-Protection header set to "1; mode=block" [ -5] Subresource Integrity (SRI) not implemented, but all external scripts are loaded over https [ -25] Content Security Policy (CSP) header not implemented -------------------------------------------------------------
Content Security Policy (CSP) header
はnot implemented
の
Score は
後日、
以上です。
[3] そも
点数が
ただ、
開発者とか
対応工数とか、
OWAZAP の
コメント