XSRF cookie does not match POST argument

2,234 views
Skip to first unread message

abdullah mohamed mohamed abdelrhim

unread,
Nov 28, 2010, 3:45:26 AM11/28/10
to python-...@googlegroups.com
i am using secure  XSRF it is ok but in first time i log in into my web i get
this error "XSRF cookie does not match POST argument" and continue without any problem even i use it many times in my web site
only first time i log in
any help

Gavin M. Roy

unread,
Nov 28, 2010, 11:55:22 AM11/28/10
to python-...@googlegroups.com
Without code of how you're implementing it in your login form, that's
difficult to diagnose. What version of Tornado are you using? Did
you put the {{ xsrf_form_html() }} snippet in?

Regards,

Gavin

abdullah mohamed mohamed abdelrhim

unread,
Nov 29, 2010, 7:31:22 AM11/29/10
to python-...@googlegroups.com
yes i but this but i use ajax function

Gavin M. Roy

unread,
Nov 29, 2010, 8:02:05 AM11/29/10
to python-...@googlegroups.com
Make sure you pass down the xsrf value in your ajax post.

On Mon, Nov 29, 2010 at 7:31 AM, abdullah mohamed mohamed abdelrhim

Josh Staiger

unread,
Nov 29, 2010, 11:22:56 AM11/29/10
to python-...@googlegroups.com
You can get the xsrf token as a cookie and pass it in your ajax post.

There's an example in the chat demo:


function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}

jQuery.postJSON = function(url, args, callback) {
    args._xsrf = getCookie("_xsrf");
    $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST",
            success: function(response) {
        if (callback) callback(eval("(" + response + ")"));
    }, error: function(response) {
        console.log("ERROR:", response)
    }});
};

Reply all
Reply to author
Forward
0 new messages