The MVC Framework Symfony uses the following method in its creation of a remember me cookie:
/**
* Generates a hash for the cookie to ensure it is not being tempered with.
*
* @param string $class
* @param string $username The username
* @param int $expires The Unix timestamp when the cookie expires
* @param string $password The encoded password
*
* @return string
*/
protected function generateCookieHash($class, $username, $expires, $password)
{
return hash_hmac('sha256', $class.$username.$expires.$password, $this->getKey());
}
So they use a string of the User Class, followed by the username, then a timestamp and then the user's password. It gets salted with a key that never changes and is equal for all the users throughout the system.
Now here is my issue with this: Why put the password in the cookie? Though it is the hashed, salted password (with another salt, unique for each user), isn't that an unnecessary risk?
Or am I being paranoid here?
Also, with that hash, it seems the only unique thing is the expires timestamp. Seems like it would be possible to copy some old cookies and create a new one for a replay attack right?
Update
The resulting Cookie is base64 encoded and its decoded content is:
Somenamespace\YourApp\YourUserClass:MjQ2NjM=:1501576079:74fbfcddcc66c2a11586bf4e39e68ddb459afa3a3fa6684e93d03fc393ee1141
The First Element is the User Class. The Second Parameter should be the base64 encoded username but this is what i get for it, so i guess it is the user id. I'll try to find out how that works too. The third Parameter is the "expires" Timestamp, so you don't even have to guess that. The fourth Parameter is said cookie hash.
generateCookieHashas well as the decoded content you pasted? As separate cookies or within the same value? – SilverlightFox Aug 01 '16 at 14:05generateCookieHashend up? – SilverlightFox Aug 01 '16 at 14:41