The ajax flag link uses a token to protect against CSRF attacks.
Currently the token only uses the entity ID. I've discussed this with the security team, whose response is that this is fine, but could do to be hardened:
* It would be great to move to something beyond md5 (since that can lead to false positives about insufficient cryptographic strength in automated scans)
* It would be great to add more data into the token beyond just entity ID
For point two, we can certainly add the flag name, action, and entity type into the token.
For point one, I could use some advice :)
Comments
Comment #1
Scyther commentedMaybe it can use the same function as the user password is using, but maybe it's to complex? See http://api.drupal.org/api/drupal/includes!password.inc/7
Comment #2
joachim commentedDo you mean http://api.drupal.org/api/drupal/includes!password.inc/function/_passwor... ?
I am not really sure what to make of that, or which bits of that to use here.
Also, one thing to bear in mind is that password encryption is a relatively rare event, as a response to a form submission. It can afford to be slow. Generating a flag link may have to be done many times on a single page load.
Comment #3
Scyther commentedLong time ago, but I think I meant that function :/
Comment #4
alexweber commented@joachim how do you want to combine entity id, flag name and action? Simple concatenation?
Comment #5
alexweber commentedAttached is a patch which does the following:
I realize there might be adjustments given I had to make a couple decisions in order to get a patch. Either way, it should serve as a good starting point for this!
Comment #6
joachim commented_password_crypt() looks like a pretty heavy function to me, and generating a token is something that has to be done for every single flag JS link. On a page like /node, or a view with flag links, that represents a lot of links. I'm concerned that it could significantly increase page load times.
I think we need input from the security team on what would be better to use than md5, but without sacrificing speed.
Comment #7
alexweber commentedOk, sounds good! Yeah, I realized that _password_crypy() might be a bit of overkill... maybe just call hash('sha256') instead? As of PHP 5.2 we can always be sure that sha256 is supported...
Can you get someone on the security team to get eyes on this?
Comment #8
gokulnk commentedI think this is a good feature to have as it improves the security. I read a few blogs and based on that I feel
hash('sha256')is good enough for generating tokens.I have re-rolled the patch and changes the hashing function as discussed in previous comments.
Comment #9
joachim commentedLet's see if the testbot likes it.
Comment #10
Scyther commentedIn patch 8
Comment #11
gokulnk commentedScyther,
Agree with you. Moving the
drupal_get_private_key()totoken_stringmakes it more readable.Updated the patch.
Comment #12
klausiwhy do you do your own logic and not just use drupal_get_token()? The comment says to work for anon users, but drupal_get_token() is able to work with anonymous users? drupal_get_token() does all the private key magic for you.
Always use "===" when comparing security related stuff. drupal_valid_token() could be used here if you just rely on drupal_get_token().
Comment #13
joachim commentedThe code is already doing something separate for anon users, so the patch isn't making that worse AFAICT.
The comment there says:
So it looks like there's a reason -- not that I understand it completely.
With some git blame & issue queue archaeology we could dig into it more, but it's going to take a bit of work, as a simple git blame of those lines hits the really annoying dump commit in our history:
Comment #14
ivnishClosed as outdated because Drupal 7 is EOL