Monday, May 21, 2018

Double Submit Cookies Using PHP



Double Submit Cookies is another CSRF prevent method,this method is differ from last method that we’ve talkd about(Synchronizer Token gen) in Double Submit Cookies we use cookies instead of session ids.










using java-script we can load csrf token into form filed with hidden values. also in here we also check user submissions in back end,whenever user request a page he/she gets a totally random value, so he/she cant predict it and perform exploitation againts legitimate users







Download Example : https://github.com/achalapramuditha/Double_Submit_Cookies-PHP

Synchronizer Token Patterns Using PHP


Synchronizer token patternSynchronizer token pattern (STP) is a technique where a token, secret and unique value for each request, is embedded by the web application in all HTML forms and verified on the server side. SPT is using for prevent CSRF attacks from the attackers.Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated. CSRF attacks specifically target state-changing requests, not theft of data, since the attacker has no way to see the response to the forged request.



To prevent CSRF attacks we can use simple method such as generating a random string in server side and append it to body of front end and check the both values when user submit web page. also we can use methods such as Check standard headers to verify the request is same origin.
Synchronizer (CSRF) Tokens
  • Any state changing operation requires a secure random token (e.g., CSRF token) to prevent CSRF attacks
  • Characteristics of a CSRF Token
    • Unique per user session
    • Large random value
    • Generated by a cryptographically secure random number generator
    • Add token to session and check it in backend
  • The CSRF token is added as a hidden field for forms or within the URL if the state changing operation occurs via a GET
  • The server rejects the requested action if the CSRF token fails validation
in these example code i’ve used an openssl function to generate a secure random string,you can find it in source code.
This how its see after CSRF protection


Download Example : https://github.com/achalapramuditha/-SynchronizerTokens-php