summaryrefslogtreecommitdiff
path: root/docs/narr
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2013-10-17 13:32:49 -0500
committerMichael Merickel <michael@merickel.org>2013-10-17 13:32:49 -0500
commit3acee31f86bcde8abbb4e63715afc5ca67976eaf (patch)
tree613b7a619d3e8846765ab51ee7d35ba518919690 /docs/narr
parent48afc25e990eb875c8e605498b13876bffce417d (diff)
downloadpyramid-3acee31f86bcde8abbb4e63715afc5ca67976eaf.tar.gz
pyramid-3acee31f86bcde8abbb4e63715afc5ca67976eaf.tar.bz2
pyramid-3acee31f86bcde8abbb4e63715afc5ca67976eaf.zip
fix documentation for csrf checking
Diffstat (limited to 'docs/narr')
-rw-r--r--docs/narr/sessions.rst18
1 files changed, 10 insertions, 8 deletions
diff --git a/docs/narr/sessions.rst b/docs/narr/sessions.rst
index 649d22bd2..f33bc6132 100644
--- a/docs/narr/sessions.rst
+++ b/docs/narr/sessions.rst
@@ -363,25 +363,27 @@ Or, include it as a header in a jQuery AJAX request:
The handler for the URL that receives the request
should then require that the correct CSRF token is supplied.
-Using the ``session.check_csrf_token`` Method
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Checking CSRF Tokens Manually
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In request handling code, you can check the presence and validity of a CSRF
-token with ``session.check_csrf_token(request)``. If the token is valid,
-it will return True, otherwise it will raise ``HTTPBadRequest``.
+token with :func:`pyramid.session.check_csrf_token(request)``. If the token is
+valid, it will return ``True``, otherwise it will raise ``HTTPBadRequest``.
+Optionally, you can specify ``raises=False`` to have the check return ``False``
+instead of raising an exception.
By default, it checks for a GET or POST parameter named ``csrf_token`` or a
header named ``X-CSRF-Token``.
.. code-block:: python
- def myview(request):
- session = request.session
+ from pyramid.session import check_csrf_token
+ def myview(request):
# Require CSRF Token
- session.check_csrf_token(request):
+ check_csrf_token(request)
- ...
+ # ...
.. index::
single: session.new_csrf_token