... om/mysite/wsgi.py WSGIPythonPath /path/to/mysite.com WSGIProcessGroup %{GLOBAL} WSGIApplicationGroup %{GLOBAL} <Location "/secret" > AuthType Basic AuthName "Top Secret" Require valid-user AuthBasicProvider wsgi WSGIAuthUserScript /path/to/mysite.com/m ... ers.modwsgi import check_password from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler () これで、 /secret/ で始まるリクエストはユーザー認証が必要になりました。 mod_wsgi の access control mechanisms documentation に、認証の代替方 ... WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py WSGIProcessGroup %{GLOBAL} WSGIApplicationGroup %{GLOBAL} <Location "/secret" > AuthType Basic AuthName "Top Secret" AuthBasicProvider wsgi WSGIAuthUserScript /path/to/mysite.com/mysite/wsgi.py WSGIA ... ... サーバーに切り替えてください。一般的な選択肢については、 WSGIサーバー または ASGIサーバー を参照してください。 最重要な設定 SECRET_KEY シークレットキーは、長いランダム文字列で、秘匿される必要があります。 本番環境で使われるキーは、他の場所で使われておらず ... 軽減できます。 設定モジュールにシークレットキーを直接書き込む代わりに、環境変数から読み込む方法を検討してください: import os SECRET_KEY = os . environ [ "SECRET_KEY" ] もしくはファイルから読み込みます: with open ( "/etc/secret_key.txt" ) as f : SECRET_KE ... Y = f . read () . strip () シークレットキーをローテーションする場合は、 SECRET_KEY_FALLBACKS : が使用できます: import os SECRET_KEY = os . environ [ "CURRENT_SECRET_KEY" ] SECRET_KEY_FALLBACKS = [ os . ... ... 的なアクセスを許可するためのワンタイムシークレットURLの生成。例えばユーザーが料金を支払ったダウンロード可能なファイルなど。 SECRET_KEY と SECRET_KEY_FALLBACKS の保護 startproject によって新しいプロジェクトを作る際、 settings.py が生成され、ランダムな SE ... ます。このキーを安全に保存するとこは極めて重要で、さもなければ攻撃を行うひとたちが彼らの署名を生成するのにも使えるからです。 SECRET_KEY_FALLBACKS は秘密鍵のローテーションに使用できます。この値はデータへの署名には使用されませんが、指定された場合は署名され ... ign ( value ) ... except signing . BadSignature : ... print ( "Tampering detected!" ) ... デフォルトでは、 Signer クラスは SECRET_KEY 設定の値を署名生成に利用します。次のように Signer のコンストラクタに任意の値を渡すことで、異なる秘密鍵を使用することも ... ... ses this format to the date filter, e.g. {{ last_updated|date:user_date_format }} , then a malicious user could obtain any secret in the application's settings by specifying a settings key instead of a date format. e.g. "SECRET_KEY" instead of "j/m/Y" ... ... s pickle to serialize session data before storing it in the backend. If you're using the signed cookie session backend and SECRET_KEY is known by an attacker (there isn't an inherent vulnerability in Django that would cause it to leak), the attacker co ... easily available on the internet. Although the cookie session storage signs the cookie-stored data to prevent tampering, a SECRET_KEY leak immediately escalates to a remote code execution vulnerability. This attack can be mitigated by serializing sessi ... ... 現在定義されているすべてのDjango設定など、環境に関する多くのメタデータが含まれています。 セキュリティ対策として、Djangoでは SECRET_KEY のような機密性の高い設定を 含めない ことにしています。具体的には、以下のいずれかを含む名前の設定は除外されます: 'API' ... 'KEY' 'PASS' 'SECRET' 'SIGNATURE' 'TOKEN' これらは 部分一致 であることに注意してください。 'PASS' は PASSWORD にも一致し、 'TOKEN' は TOKENIZED ... 属性を設定することで、リクエストごとにオーバーライドできます。詳細については Django のリクエスト処理 を参照してください。 SECRET_KEY デフォルト値: '' (空文字列) Django のインストールごとに設定される個別の秘密鍵です。 暗号署名 に使われる鍵であり、ユニー ... ... ses this format to the date filter, e.g. {{ last_updated|date:user_date_format }} , then a malicious user could obtain any secret in the application's settings by specifying a settings key instead of a date format. e.g. "SECRET_KEY" instead of "j/m/Y" ... ... w from .views import VoteView urlpatterns = [ path ( "about/" , login_required ( TemplateView . as_view ( template_name = "secret.html" ))), path ( "vote/" , permission_required ( "polls.can_vote" )( VoteView . as_view ())), ] このアプローチではデコレー ... port method_decorator from django.views.generic import TemplateView class ProtectedView ( TemplateView ): template_name = "secret.html" @method_decorator ( login_required ) def dispatch ( self , * args , ** kwargs ): return super () . dispatch ( * args ... もあります。 @method_decorator ( login_required , name = "dispatch" ) class ProtectedView ( TemplateView ): template_name = "secret.html" 共通のデコレータ群が複数の場所で呼ばれる場合には、デコレータのリストまたはタプルを定義して、これを method_decorator( ... ... ... ngo" , }, "other" : { "ENGINE" : "django.contrib.gis.db.backends.postgis" , "NAME" : "other" , "USER" : "geodjango" , }, } SECRET_KEY = "django_tests_secret_key" 上記の設定が runtests.py と同じディレクトリにある postgis.py ファイルにあるとすると、コマン ... 2026年10月08日