I am working on the security issues for my web application. And i have to deal with the CSRF. Gone through many refrences but some of them uses Cookie while other uses SESSION .
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For CSRF prevention you need to store a shared token on both the client and the server, so when the client makes a request, their submitted value can be compared with your known value.
For the client side you could use a cookie, or a hidden form field (personally I prefer the hidden field – so I don’t pile up cookies for every form in the clients browser).
On the server you could use the session (where the session id is stored in a cookie anyway) or store it in a database (although you’d probably need to use the session to identify the record that belongs to the client).
Here’s some very basic example CSRF prevention code for you.