I am using Codeigniter and i enabled CSRF via its config.php file…
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_token_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
then on my ajax requests i get the cookie name
var cct = $.cookie('csrf_cookie_name');
and on parameters:
csrf_token_name : cct
My question: Do i need to do anything else or that’s it?
Okay, most common case (or easiest to implement) of CSRF is something like this:
So if you’re assuming that you’re logged into
bank.example.comyou’re cookies are “alive” and will be send with request, so request will do what attacker want it to, so:Cookies won’t protect you from CSRF
What can you do:
Send as many request via
POSTas you can (without bothering the user), especially edits, creations and deletion. It’s easier to hide security intoinput type='hidden'than into URL.Check referrer (yeah, this little thing prevents you from almost every CSRF attack from external sites):
Add temporary security tokens to URLs like this
/article/delete/25/axdefm…If you’ve spent some time generating nice URLs you’ll be send because this will just screw them up and this brings on some problems such as:
Solution
You may create table for security tokens, such as this one:
And when some action requires authorization token you’ll load last one from DB or create new one, let’s say you will create new token only if all available tokes are older than 15 minutes:
How will this act:
How to check token?
If you wan’t to make sure that action won’t happen twice (such as edit article, this works fine for deletion) just add
revision_numberor something similar to your$eventIdentificator).Try to think what will happen if:
I’d go with mentioned token system, it feels like a balanced solution between user comfort/implementation complexity and security, comments with ideas and notes are expected 🙂