首页 > 解决方案 > Wagtail: Intermittent CSRF Verification Error

问题描述

When saving a draft, I have been getting a "CSRF verification failed. Request aborted." error. It happens only intermittently, trying a couple of times to save the draft usually works. I am running Wagtail 2.2.2 and Django 2.0.3, and I have 'django.middleware.csrf.CsrfViewMiddleware' in my settings.py file. Here is the error message:

Forbidden (403)
CSRF verification failed. Request aborted.

Reason given for failure:
CSRF token missing or incorrect.

标签: djangowagtail

解决方案


This is due to a custom implementation of Shibboleth my organization uses for authentication. It seems that if I previewed a page before saving the draft, the CSRF token was changed by Django, which Shib did not like. In our own code, we extend RemoteUserMiddleware to use with Shib. So, we changed that to PersistentRemoteUserMiddleware and it seems to be working now.


推荐阅读