An anti-CSRF token is created and stored in the user session and in a hidden field on subsequent form submits. At every submit, the server checks the token from the session matches the one submitted from the form.
How to implement
For the ease of you implementation you can download my source code from below link.
https://github.com/tharushi-pushpakumara/Cross-site-Request-Forgery-with-Synchronizer-Token-Patterns
Basically we need 3 php files.
- control.php
- index.php
- logout.php
Index.php
This is the main page and it's php code to validate the credentials.
This is one way to be protected from CSRF attacks. Double submit cookie is an another way to be protected from this type of attack.
No comments:
Post a Comment