javascript - csrf issue from node js to django -
i want pass csrftoken node.js django. have code in server.js
socket.on('unread global', function (data) { var values=querystring.stringify(); var options = { hostname:'localhost', port:'8000', path:'/chat/global_unread/', method:'post', headers:{ 'content-type':'application/x-www-form-urlencoded', 'cookie': 'csrftoken=' + data.csrf, 'content-length':values.length } }
my data come jquery function calls server.js
var datos = { // datos data send node.js user: user_pk_chat, csrf : window.csrf_token }; socket.emit('unread global', datos);
but @ end same error in console
reason given failure:
csrf token missing or incorrect.
in general, can occur when there genuine cross site request forgery, or when
for post forms, need ensure:
your browser accepting cookies... on can sombody me?
the csrf middleware looks following cookie:
request.cookies[settings.csrf_cookie_name]
and compare post csrfmiddlewaretoken.
so have make sure call node sets correct cookie name in:
'cookie': 'csrftoken=' + data.csrf`
and also, post includes csrfmiddlewaretoken
. it's safe access cookie in javascript , send correct token, make sure use csrf_cookie_secure. better way let django put token input field, , set cookie separately.
Comments
Post a Comment