2013-11-02 16:30:39 +08:00
|
|
|
from django.conf import settings
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
from django.http import HttpResponseForbidden
|
|
|
|
from django.template import Context, Template
|
2013-11-02 16:30:39 +08:00
|
|
|
from django.utils.translation import ugettext as _
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
|
|
|
|
# We include the template inline since we need to be able to reliably display
|
|
|
|
# this error message, especially for the sake of developers, and there isn't any
|
|
|
|
# other way of making it available independent of what is in the settings file.
|
|
|
|
|
2013-11-02 16:30:39 +08:00
|
|
|
# Only the text appearing with DEBUG=False is translated. Normal translation
|
|
|
|
# tags cannot be used with this inline templates as makemessages would not be
|
|
|
|
# able to discover the strings.
|
|
|
|
|
2011-05-12 11:03:16 +08:00
|
|
|
CSRF_FAILURE_TEMPLATE = """
|
2011-04-21 01:40:53 +08:00
|
|
|
<!DOCTYPE html>
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
2010-05-23 02:42:16 +08:00
|
|
|
<meta name="robots" content="NONE,NOARCHIVE">
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
<title>403 Forbidden</title>
|
2010-05-23 02:42:16 +08:00
|
|
|
<style type="text/css">
|
|
|
|
html * { padding:0; margin:0; }
|
|
|
|
body * { padding:10px 20px; }
|
|
|
|
body * * { padding:0; }
|
|
|
|
body { font:small sans-serif; background:#eee; }
|
|
|
|
body>div { border-bottom:1px solid #ddd; }
|
|
|
|
h1 { font-weight:normal; margin-bottom:.4em; }
|
|
|
|
h1 span { font-size:60%; color:#666; font-weight:normal; }
|
|
|
|
#info { background:#f6f6f6; }
|
|
|
|
#info ul { margin: 0.5em 4em; }
|
2010-09-04 00:28:10 +08:00
|
|
|
#info p, #summary p { padding-top:10px; }
|
2010-05-23 02:42:16 +08:00
|
|
|
#summary { background: #ffc; }
|
|
|
|
#explanation { background:#eee; border-bottom: 0px none; }
|
|
|
|
</style>
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
</head>
|
|
|
|
<body>
|
2010-05-23 02:42:16 +08:00
|
|
|
<div id="summary">
|
2013-11-02 16:30:39 +08:00
|
|
|
<h1>{{ title }} <span>(403)</span></h1>
|
|
|
|
<p>{{ main }}</p>
|
2010-09-04 00:28:10 +08:00
|
|
|
{% if no_referer %}
|
2013-11-02 16:30:39 +08:00
|
|
|
<p>{{ no_referer1 }}</p>
|
|
|
|
<p>{{ no_referer2 }}</p>
|
2010-09-04 00:28:10 +08:00
|
|
|
{% endif %}
|
2010-05-23 02:42:16 +08:00
|
|
|
</div>
|
|
|
|
{% if DEBUG %}
|
|
|
|
<div id="info">
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
<h2>Help</h2>
|
|
|
|
{% if reason %}
|
|
|
|
<p>Reason given for failure:</p>
|
|
|
|
<pre>
|
|
|
|
{{ reason }}
|
|
|
|
</pre>
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
<p>In general, this can occur when there is a genuine Cross Site Request Forgery, or when
|
|
|
|
<a
|
|
|
|
href='http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ref-contrib-csrf'>Django's
|
|
|
|
CSRF mechanism</a> has not been used correctly. For POST forms, you need to
|
|
|
|
ensure:</p>
|
|
|
|
|
|
|
|
<ul>
|
2012-02-22 07:54:02 +08:00
|
|
|
<li>Your browser is accepting cookies.</li>
|
|
|
|
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
<li>The view function uses <a
|
2009-10-29 22:17:39 +08:00
|
|
|
href='http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext'><code>RequestContext</code></a>
|
|
|
|
for the template, instead of <code>Context</code>.</li>
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
|
2009-10-29 22:17:39 +08:00
|
|
|
<li>In the template, there is a <code>{% templatetag openblock %} csrf_token
|
|
|
|
{% templatetag closeblock %}</code> template tag inside each POST form that
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
targets an internal URL.</li>
|
2009-11-03 22:40:37 +08:00
|
|
|
|
|
|
|
<li>If you are not using <code>CsrfViewMiddleware</code>, then you must use
|
|
|
|
<code>csrf_protect</code> on any views that use the <code>csrf_token</code>
|
|
|
|
template tag, as well as those that accept the POST data.</li>
|
|
|
|
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
</ul>
|
|
|
|
|
|
|
|
<p>You're seeing the help section of this page because you have <code>DEBUG =
|
|
|
|
True</code> in your Django settings file. Change that to <code>False</code>,
|
|
|
|
and only the initial error message will be displayed. </p>
|
|
|
|
|
|
|
|
<p>You can customize this page using the CSRF_FAILURE_VIEW setting.</p>
|
2010-05-23 02:42:16 +08:00
|
|
|
</div>
|
|
|
|
{% else %}
|
|
|
|
<div id="explanation">
|
2013-11-02 16:30:39 +08:00
|
|
|
<p><small>{{ more }}</small></p>
|
2010-05-23 02:42:16 +08:00
|
|
|
</div>
|
|
|
|
{% endif %}
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""
|
|
|
|
|
2013-11-02 16:30:39 +08:00
|
|
|
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
def csrf_failure(request, reason=""):
|
|
|
|
"""
|
|
|
|
Default view used when request fails CSRF protection
|
|
|
|
"""
|
2010-09-04 00:28:10 +08:00
|
|
|
from django.middleware.csrf import REASON_NO_REFERER
|
2011-05-12 11:03:16 +08:00
|
|
|
t = Template(CSRF_FAILURE_TEMPLATE)
|
2013-11-02 16:30:39 +08:00
|
|
|
c = Context({
|
|
|
|
'title': _("Forbidden"),
|
|
|
|
'main': _("CSRF verification failed. Request aborted."),
|
|
|
|
'reason': reason,
|
|
|
|
'no_referer': reason == REASON_NO_REFERER,
|
|
|
|
'no_referer1': _(
|
|
|
|
"You are seeing this message because this HTTPS site requires a "
|
|
|
|
"'Referer header' to be sent by your Web browser, but none was "
|
|
|
|
"sent. This header is required for security reasons, to ensure "
|
|
|
|
"that your browser is not being hijacked by third parties."),
|
|
|
|
'no_referer2': _(
|
|
|
|
"If you have configured your browser to disable 'Referer' headers, "
|
|
|
|
"please re-enable them, at least for this site, or for HTTPS "
|
|
|
|
"connections, or for 'same-origin' requests."),
|
|
|
|
'DEBUG': settings.DEBUG,
|
|
|
|
'more': _("More information is available with DEBUG=True."),
|
|
|
|
})
|
2012-07-01 03:19:07 +08:00
|
|
|
return HttpResponseForbidden(t.render(c), content_type='text/html')
|