簡體   English   中英

為什么我會收到這些 Django 安全警告,但團隊中的其他開發人員卻沒有

[英]Why am I getting these Django security warnings, but not other developers on the team

我目前在運行 makemigrations 時收到以下 Django 安全警告:

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.) 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.W019) You have 'django.middleware.clickjacking.XFrameOptionsMiddleware' in your MIDDLEWARE_CLASSES, 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'.

隨后是一組其他警告。 我計划解決這些警告,但我不明白為什么我團隊中的其他人都沒有收到這些警告。 我正在使用 Python virtualenv。 有沒有人知道為什么我是唯一一個收到這些警告的人?

我還確認我沒有使用另一台計算機收到這些警告,它只是我的開發機器。

這可能是您使用的 Django 版本。 1.8 及更高版本使用 HSTS

第一個警告是關於 HSTS 標頭,它阻止瀏覽器訪問 HTTP 中的數據。 它通常設置為 1 年,即 31536000 秒。 但在測試條件下,您可能更喜歡使用較低的值,例如 60 秒或 3600 秒。

SECURE_HSTS_SECONDS = 31536000

第二個警告是防止嗅探攻擊。 這可以通過在 settings.py 中添加以下行來防止

SECURE_CONTENT_TYPE_NOSNIFF = True

文件:

  1. 關於 HSTS 設置( 此處)
  2. 關於 NOSNIFF
  3. 其他安全中間件

似乎升級了 django 版本,但沒有升級您的中間件。 確保安全中間件在它們之間。

更多信息https://docs.djangoproject.com/en/3.2/topics/http/middleware/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM