Double Submit Cookies Pattern
Cross-Site Request Forgery (CSRF)
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. With a little help of social
engineering (such as sending a link via email or chat), an attacker may trick
the users of a web application into executing actions of the attacker's
choosing. If the victim is a normal user, a successful CSRF attack can force
the user to perform state changing requests like transferring funds, changing
their email address, and so forth. If the victim is an administrative account,
CSRF can compromise the entire web application.
Cross-site Request Forgery(CSRF) protection via Double Submit Cookies Patterns.
In this technique, we
send a random value in both a cookie and as a request parameter, with the
server verifying if the cookie value and request value match. When a user
visits (even before authenticating to prevent login CSRF), the site should
generate a (cryptographically strong) pseudorandom value and set it as a cookie
on the user's machine separate from the session identifier. The site then
requires that every transaction request include this pseudorandom value as a
hidden form value (or other request parameter/header). If both of them match at
server side, the server accepts it as legitimate request and if they don’t, it
would reject the request.
Implementation
User needs to login to
the wesite.
(username
“user” password “user”)
| Login Page |
When
user clicked on “Login” button, invoke token.php to generate csrf token and
cookie
| token.php |
Successful login user
will be redirected to the moneyTransfer page (moneyTransfer.php). At the same
time created token and cookie set to the hidden fields (tokenRequest.js)
| Money Transfer Page |
tokenRequest.js
|

Comments
Post a Comment