============================================== クロスサイトリクエストフォージェリ (CSRF) 対策 ============================================== :revision-up-to: 17812 (1.4) .. module:: django.middleware.csrf :synopsis: Protects against Cross Site Request Forgeries .. The CSRF middleware and template tag provides easy-to-use protection against `Cross Site Request Forgeries`_. This type of attack occurs when a malicious Web site contains a link, a form button or some javascript that is intended to perform some action on your Web site, using the credentials of a logged-in user who visits the malicious site in their browser. A related type of attack, 'login CSRF', where an attacking site tricks a user's browser into logging into a site with someone else's credentials, is also covered. CSRF ミドルウェアとテンプレートタグは、簡単に使える `クロスサイトリクエストフォージェリ (Cross Site Request Forgeries)`_ 対策を提供しています。このタイプの攻撃は、悪意のあるウェブサイトを訪れたユーザー のログイン済みの権限で、あなたのサイトに対して何らかの操作を行うことを目的とした リンクやフォームボタン、 JavaScript を設置したウェブサイトによって行われます。 また、関連する攻撃として、ユーザーを騙して別のユーザー権限でログインさせる ログイン CSRF と呼ばれる攻撃もありますが、これも含まれます。 .. The first defense against CSRF attacks is to ensure that GET requests (and other 'safe' methods, as defined by 9.1.1 Safe Methods, HTTP 1.1, :rfc:`2616#section-9.1.1`) are side-effect free. Requests via 'unsafe' methods, such as POST, PUT and DELETE, can then be protected by following the steps below. CSRF 攻撃に対する第一の防御は、 GET (と、9.1.1 Safe Methods,HTTP 1.1, :rfc:`2616#section-9.1.1` で定義された '安全な' メソッド) リクエストから副作用を 取り除くというものです。そして、 POST, PUT, DELETE のような、'安全でない' メソッ ドによるリクエストについては、下記の手順に従うことで対策することができます。 .. _Cross Site Request Forgeries: http://www.squarefree.com/securitytips/web-developers.html#CSRF .. _`クロスサイトリクエストフォージェリ (Cross Site Request Forgeries)`: `Cross Site Request Forgeries`_ .. _using-csrf: 使い方 ============= .. To enable CSRF protection for your views, follow these steps: CSRF 対策をあなたのビューで有効にするには、以下の手順に従ってください。: .. 1. Add the middleware ``'django.middleware.csrf.CsrfViewMiddleware'`` to your list of middleware classes, :setting:`MIDDLEWARE_CLASSES`. (It should come before any view middleware that assume that CSRF attacks have been dealt with.) Alternatively, you can use the decorator :func:`~django.views.decorators.csrf.csrf_protect` on particular views you want to protect (see below). 1. ``'django.middleware.csrf.CsrfViewMiddleware'`` ミドルウェアを :setting:`MIDDLEWARE_CLASSES` に追加してください。 (このミドルウェアは、 CSRF 対策が為されていることを前提として動作するどのミドルウェアよりも前に 追加します。) また、代わりに 対策したい特定のビューに対して、 :func:`~django.views.decorators.csrf.csrf_protect` デコレータを使用することも できます (下記参照) .. 2. In any template that uses a POST form, use the :ttag:`csrf_token` tag inside the ``