Reputation: 131
What I've understood, CSRF-Attacks works like this:
To prevent this websites are using a Token that is generated random by the webpage, and stored as a session, then your webpage sends this token with the request, as a parameter. Since that make the website know the user really visited the website and performed the action.
Instead of sending a token as a parameter. Can you just send the logged in cookie as a parameter?
Since cookies are webiste-specific, I can not see a way another page would be able to send this cookie as a parameter to your website.
Upvotes: 1
Views: 69
Reputation: 33538
Yes you can, assuming "logged in cookie" is a cryptographically secure session identifier.
This method of CSRF defence is known as Double Submit Cookies:
Double submitting cookies is defined as sending a random value in both a cookie and as a request parameter, with the server verifying if the cookie value and request value are equal.
Normally this value is separate than the session ID, but there is no reason not to use it if your session IDs are static.
In a CSRF attack, the attacker can only submit the victim's cookies to the target site using the victim's browser. There is no way of the attacker actually reading the cookie value, nor a copy of this value set as a POST parameter. So, double submit cookies is a good CSRF defence.
Note that using a GET parameter is not recommended, as this value can be leaked in the referer
header.
Upvotes: 2
Reputation: 131
I found out why this wont work, if you send your cookie as a parameter there will always be a way for the attacker to use that (jquery?)function, or similar. Therefore you will always have to get the token from the webpage. You could maybe print the cookie and then get it that way, but it would just be easier to make a session token as an hidden input to the website.
Upvotes: 0