Django comes with CSRF middleware protection that generates a unique token for each session for use in forms. It scans all incoming POST requests for the correct token and rejects the request if the token is missing or invalid.
I would like to use AJAX for some POST requests, but the requests mentioned do not have an available CSRF token. Pages do not have <form> elements, and I do not want to stir up the markup by inserting a token into a hidden value. I believe that a good way to do this is to set vew to /get-csrf-token/ in order to return the user token based on the cross-site scripting rules of the browser to prevent unwanted sites from requesting it.
Is that a good idea? Are there better ways to protect against CSRF attacks while resolving AJAX requests?
security ajax django csrf
John Millikin Sep 27 '08 at 23:11 2008-09-27 23:11
source share