####
## Community authentication endpoint
####
-from django.views.decorators.csrf import csrf_protect
@ssl_required
-@csrf_protect
def communityauth(request, siteid):
# Get whatever site the user is trying to log in to.
site = get_object_or_404(CommunityAuthSite, pk=siteid)
@ssl_required
-@csrf_protect
def communityauth_logout(request, siteid):
# Get whatever site the user is trying to log in to.
site = get_object_or_404(CommunityAuthSite, pk=siteid)
MIDDLEWARE_CLASSES = [
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'util.middleware.PgMiddleware',
]
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.db import connection
from django.template.defaultfilters import slugify
+from django.views.decorators.csrf import csrf_exempt
from pgweb.util.contexts import NavContext
from pgweb.util.misc import get_client_ip
'surveylist': surveylist,
}, NavContext(request, 'community'))
+# Served over insecure HTTP, the Varnish proxy strips cookies
+@csrf_exempt
def vote(request, surveyid):
surv = get_object_or_404(Survey, pk=surveyid)
{%block title%}Edit user profile{%endblock%}
{%block contents%}
<h1>Edit user profile</h1>
-<form method="post" action=".">
+<form method="post" action=".">{% csrf_token %}
<table class="pgGenericFormTable">
{%if form.errors%}
{%block title%}{{operation|default:"Edit"}} {{formitemtype}}{%endblock%}
{%block contents%}
<h1>{{operation|default:"Edit"}} {{formitemtype}}</h1>
-<form method="post" action=".">
+<form method="post" action=".">{% csrf_token %}
{%if form_intro%}
<p>
{{form_intro|safe}}
{%block content%}
<div id="content-main">
<h1>Merge organisations</h1>
-<form method="post" action=".">
+<form method="post" action=".">{% csrf_token %}
<table>
{{form.as_table}}
</table>
</div>
{%endif%}
- <form method="POST" action=".">
+ <form method="POST" action=".">{% csrf_token %}
URL (regex): <input type="text" name="url">
<input type="submit" value="Purge" />
</form>
<dt>User Survey</dt>
<dd>{{survey.question}}</dd>
<dd>
- <form method="post" action="/community/survey/vote/{{survey.id}}/">
+ <form method="post" action="/community/survey/vote/{{survey.id}}/"><!-- CSRF exempt -->
<p>
{%for q in survey.questions%}
<input type="radio" name="answer" value="{{q.value}}" id="surv_opt_{{q.value}}" /><label for="surv_opt_{{q.value}}">{{q.text}}</label><br />