Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP Cookies getting scrambled - Suhosin related

For some reason I am unable to read any cookies from my CakePHP app on any page after they have been set, the only thing that is returned is garbled text.

My code is as simple as this:

$this->Cookie->write('Region', 'test');
$reg = $this->Cookie->read('Region');
pr($reg);

I uncomment the $this->Cookie->write() line and all I get back is a bunch of random control characters. I also recently upgraded to CakePHP 1.3 but AFAIK this should not effect cookie like this... This was working fine until I changed server, this must be the root of my problem.

Update After probing around further I have discovered this is a known issue with the Suhosin security patch for PHP effecting the rand() and srand() methods, I had configured Suhosin to allow the rand() functions but still it is happening, is there a more effective work around out there?

like image 687
Dunhamzzz Avatar asked Jan 18 '11 12:01

Dunhamzzz


2 Answers

Try this code which will disable cookie encryption:

$this->Cookie->write('Region', 'test', false);
$reg = $this->Cookie->read('Region');
pr($reg);

The write method has the following params:

write(mixed $key, mixed $value, boolean $encrypt, mixed $expires)

By default all values in the cookie are encrypted by CakePHP. However for security reasons you may wish to look into working with the encryption.

like image 147
Chris Kempson Avatar answered Sep 30 '22 00:09

Chris Kempson


CakePHP encrypts cookies by default.

Is your Security.salt value the same in this new installation?

How about the $key value in your cookie controller setup?

like image 33
Mark Snidovich Avatar answered Sep 30 '22 00:09

Mark Snidovich