CSRF token missing or incorrect. When try to login

8,362 views
Skip to first unread message

Chetan Parekh

unread,
May 30, 2014, 9:38:54 AM5/30/14
to edx-...@googlegroups.com
Hello All,

I have get this error, when try to login in LMS edx.
Can anyone suggest why this error comes?
Thanks in advance.

Error : 

Forbidden (403)

CSRF verification failed. Request aborted.

Help

Reason given for failure:

    CSRF token missing or incorrect.
    

In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure:

  • Your browser is accepting cookies.
  • The view function uses RequestContext for the template, instead of Context.
  • In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
  • If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.

You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.

You can customize this page using the CSRF_FAILURE_VIEW setting.


Thanks,

Chetan Parekh

David Baumgold

unread,
May 30, 2014, 9:42:57 AM5/30/14
to edx-...@googlegroups.com
CSFR stands for Cross-Site Request Forgery: see https://en.wikipedia.org/wiki/Cross-site_request_forgery. In order to prevent this kind of vulnerability, forms pass around special CSRF verification tokens, to validate POST requests as authentic. The error you’re seeing indicates that the page didn’t pass the necessary CSRF verification token when trying to log in, and so the web server blocked the login attempt.

I’ve seen this error before when there was a problem compiling coffeescript. Can you verify that that’s working properly?
-David Baumgold

Chetan Parekh

unread,
May 31, 2014, 10:40:26 AM5/31/14
to edx-...@googlegroups.com
Hello,

Solve this problem, as two jQuery was loading inside the code. 
Second jQuery erased jQuery.cookie object.

Thanks,
Chetan Parekh

hsin han Liu

unread,
Aug 1, 2014, 3:36:57 AM8/1/14
to edx-...@googlegroups.com
hi

can you specify how you fix the problem?

Chetan Parekh於 2014年5月31日星期六UTC+8下午10時40分26秒寫道:

ankur.z...@pilani.bits-pilani.ac.in

unread,
Apr 6, 2015, 10:53:33 AM4/6/15
to edx-...@googlegroups.com
Hello Chetan,

Can you please specify the fix for the issue?

tojo cherian

unread,
Feb 26, 2017, 2:13:33 PM2/26/17
to General Open edX discussion, chetan....@gmail.com

Please mention how this issue can be fixed

dim kar

unread,
May 6, 2018, 8:40:30 AM5/6/18
to General Open edX discussion
You could change the cache.py file into the path directory:  /edx/app/edxapp/edx-platform/common/djangoapps/utils/cache.py

The only thing that you must do is to change the def wrapper funvction adding the command "return view_func(request, *args, **kwargs)" as below. Using that command you don't cache the pages so the crfs tokens can be changed.

    def decorator(view_func):
        """The outer wrapper, used to allow the decorator to take optional arguments."""
        @wraps(view_func)
        def wrapper(request, *args, **kwargs):
            return view_func(request, *args, **kwargs)
            """The inner wrapper, which wraps the view function."""
            # Certificate authentication uses anonymous pages, 

Gautam Chatterjee

unread,
Jul 3, 2018, 9:39:24 AM7/3/18
to General Open edX discussion
Hi Chetan,

How did you fix this issue. Can you please help? Since 3 months I am stuck in the same issue.
Reply all
Reply to author
Forward
0 new messages