简体   繁体   中英

rails 3 CSRF token changes just before the POST request

Rails 3 , Backbone.js app.

The CSRF token does not change until a POST form is submitted.

As soon as form is submitted the CSRF token changes and i get "WARNING: Can't verify CSRF token authenticity"

Form is submitted using ajax.

I guess it is kind of too late to respond, but most likely the problem caused by missing withCredentials parameter of XHR requests you are sending from the Backbone.js. If your POST request does not contain session infromation, it will be given new CSRF token by your backend.

$.ajax({
 type: "POST",
 xhrFields: {withCredentials: true},
 //other fields
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM