Monday, May 14, 2018

Cross-site Request Forgery protection in web applications via Synchronizer Token Patterns


Cross-Site Request Forgery is done with attacker tricking a victim into making a request he did not intend to do. As in above diagram attacker manipulate the trust application has on victims browser. 




To do this attack there have to be 2 requirments fulfilled.

1.The victim should be logged in to the targeted website (have an active session)
2. The site should be vulnerable to cross-site scripting forgery

The attack is against authenticated web application using a cookie.
Synchronizer token patterns is a method to prevent this from happening. This article discusses on how it works.

  • First I have created my login page. This is where the user enters the credentials to log in to a certain website.




  • The session starts on the client side and a cookie is created using the session id.



  • At the same time, the server side randomly generates a key and use it to generate the CSRF token. CSRF token is saved in a session variable for future use.



  • Then the loadDoc function is created in java script to request the token that created from the client side and to place it in the html tag.



  • The loadDoc function should be called with the method, server-side URL and the HTML tag for the form.





  • This is the HTML form for credentials. Here you can see a hidden field with the id = Token. This hidden file stores the token and send it to the server by POST method.



  • In the server side, the data that was sent from the post method are assigned as parameters for loginvalidate function.




  • By comparison from the credentials are validated and the Tokens and session ids are compared.
  • If all 4 matches access granted. Else an error message will be displayed.



No comments:

Post a Comment

Review of California Consumer Privacy Act (CCPA) and the amendment of California Privacy Rights Act (CPRA)

California Consumer Privacy Act (CCPA) became effective on 1st of January 2020 enhancing the privacy rights and consumer protection for the ...