I am adding CSRF prevention mechanism to my application. I have look through many posts but just still have uncertainties in my approach. I am going to use the synchronized token implementation at the same time I want to use it to prevent double submit, back button and refresh. so I will need a new token for every request. Currently in my app, there are the regular form submit, url GET and AJAX requests. There are actually some new-window popups, but I am trying eliminate/rewrite those functions. Here is what I am planing to do along with some uncertainties.
Here is some preliminary assumptions:
- under normal circumstances no two functions will send request to server at same time from one user
- prevented all XSS
- cannot access cookie with JavaScript
- using HTTPS
My flow and doubts:
- token will be generated and stored in session then passed along with generated HTML or JSON data. Will value transmitted through header be as secure as inserting it in HTML or JSON?
- every request will carry this token to be matched against the value stored in session. will passing this value through header be of any problem?
- in order to minimize my programmers' work, I want to provide uniform JavaScript functions to submit form and make AJAX call so I can add the token on the request transparently. Therefore, I plan to put the token in a JavaScript variable which will definitely be accessible by all JavaScript programs. Is there any risk for doing this?
Does my approach have the "self-contained" problem?
Thanks