Django

Code

Show
Ignore:
Timestamp:
12/17/06 21:59:45 (2 years ago)
Author:
adrian
Message:

Negligible spacing changes to docs/csrf.txt to be consistent

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/csrf.txt

    r2980 r4224  
    11===================================== 
    2 Cross Site Request Forgery Protection 
     2Cross Site Request Forgery protection 
    33===================================== 
    44 
    5 The CsrfMiddleware class provides easy-to-use protection against  
    6 `Cross Site Request Forgeries`_.  This type of attack occurs when a malicious  
     5The CsrfMiddleware class provides easy-to-use protection against 
     6`Cross Site Request Forgeries`_.  This type of attack occurs when a malicious 
    77web site creates a link or form button that is intended to perform some action 
    88on your web site, using the credentials of a logged-in user who is tricked 
     
    1313middleware into your list of installed middleware. 
    1414 
    15  
    1615.. _Cross Site Request Forgeries:  http://www.squarefree.com/securitytips/web-developers.html#CSRF 
    1716 
    1817How to use it 
    1918============= 
    20 Add the middleware ``'django.contrib.csrf.middleware.CsrfMiddleware'`` to  
     19 
     20Add the middleware ``'django.contrib.csrf.middleware.CsrfMiddleware'`` to 
    2121your list of middleware classes, ``MIDDLEWARE_CLASSES``. It needs to process 
    2222the response after the SessionMiddleware, so must come before it in the 
     
    2626How it works 
    2727============ 
     28 
    2829CsrfMiddleware does two things: 
    2930 
    30 1. It modifies outgoing requests by adding a hidden form field to all  
    31    'POST' forms, with the name 'csrfmiddlewaretoken' and a value which is  
    32    a hash of the session ID plus a secret. If there is no session ID set,  
    33    this modification of the response isn't done, so there is very little  
     311. It modifies outgoing requests by adding a hidden form field to all 
     32   'POST' forms, with the name 'csrfmiddlewaretoken' and a value which is 
     33   a hash of the session ID plus a secret. If there is no session ID set, 
     34   this modification of the response isn't done, so there is very little 
    3435   performance penalty for those requests that don't have a session. 
    3536 
    36 2. On all incoming POST requests that have the session cookie set, it  
    37    checks that the 'csrfmiddlewaretoken' is present and correct. If it  
     372. On all incoming POST requests that have the session cookie set, it 
     38   checks that the 'csrfmiddlewaretoken' is present and correct. If it 
    3839   isn't, the user will get a 403 error. 
    3940 
     
    4445POST forms). GET requests ought never to have side effects (if you are 
    4546using HTTP GET and POST correctly), and so a CSRF attack with a GET 
    46 request will always be harmless.  
     47request will always be harmless. 
    4748 
    4849POST requests that are not accompanied by a session cookie are not protected, 
     
    5051could make these kind of requests anyway. 
    5152 
    52 The Content-Type is checked before modifying the response, and only  
     53The Content-Type is checked before modifying the response, and only 
    5354pages that are served as 'text/html' or 'application/xml+xhtml' 
    5455are modified. 
     
    5657Limitations 
    5758=========== 
     59 
    5860CsrfMiddleware requires Django's session framework to work. If you have 
    5961a custom authentication system that manually sets cookies and the like, 
    6062it won't help you. 
    6163 
    62 If your app creates HTML pages and forms in some unusual way, (e.g.  
    63 it sends fragments of HTML in javascript document.write statements)  
    64 you might bypass the filter that adds the hidden field to the form,  
     64If your app creates HTML pages and forms in some unusual way, (e.g. 
     65it sends fragments of HTML in javascript document.write statements) 
     66you might bypass the filter that adds the hidden field to the form, 
    6567in which case form submission will always fail.  It may still be possible 
    6668to use the middleware, provided you can find some way to get the 
    6769CSRF token and ensure that is included when your form is submitted. 
    68