|
|
|
[
Permlink
| « Hide
]
Thomas Weidner - 16/Aug/07 01:32 PM
Assigned to Shahar
The same problem.
For example: And we have urlencoded session incorrect value: Cookie value can contain ":" and other escaped symbols. I also got bitten by this really nasty bug. Very hard to figure out what's going on. The following bug in PEAR along with the fix might also be worth a look (if clean IP does not scare you off from looking at it):
http://pear.php.net/bugs/bug.php?id=1080 The relevant RFC's fail to discuss encoding of specialchars like semicolon, equal or newline all together:
http://www.faqs.org/rfcs/rfc2109.html http://www.faqs.org/rfcs/rfc2965 General consensus on the web seems to be that v0 cookies do not define any encoding. Using urlencoding seems to be a popular approach though, supposedly for v1 cookies. That being said in this case the encoding needs to be applied to both the name and the value. There are however obviously servers that do not support v1 cookies and which will run into issues with urlencoding. For these there should be an option to skip urlencoding entirely. Ok after some discussion with Dave Kristol (http://kristol.org/cookie/errata.html
So when sending a cookie, it should only do whatever encoding that was decoded previously. In many cases urlencoding might be a reasonable default, but in many cases it isnt. So I suggest to do the following: 1) also url encode/decode the name by default Zend_Http_Client is also affected by this issue, as there is also code in there that forced urlencode() on cookie values.
Here is a solution for just passing through the cookie that was send to PHP. This way when PHP is sitting between the user browser and the original server that set the cookie as a proxy, the cookie is passed through without change to the server that set the cookie.
class My_Zend_Http_Client extends Zend_Http_Client
$this->headers['cookie'] = array('Cookie', $_SERVER['HTTP_COOKIE']); Because this issue touches both Zend_Http_Cookie, Zend_Http_Client and in a way Zend_Http_Cookiejar - I think an ideal solution would be:
1. Whatever is received from the server (through Zend_Http_Cookiejar, Zend_Http_Cookie::fromString() etc. is stored and sent back just the way it is 2. Any cookies added manually by the user can be either encoded or not - depending on an additional parameter to Zend_Http_Client->setCookie(). By default it will be true (do encoding) in order to maintain BC. As a general rule, how does this sound? So to be able to pass through the cookies of the current request without any parsing I could do the following?
$client = new Zend_Http_Client($url, $opts); That seems like a workable approach to me. Yeah - that would work.
It might also make good sense to add an API to quickly do that - but honestly I think this is quite advanced usage so just to save a line of code I think it's not required. Also, while I am focusing on the encode part. The same situation also needs to be addressed for the decoding stage. The raw cookie needs to be available in the response.
I do not agree that its so advanced. This situation will come up whenever PHP sits as a proxy between a browser and a server, where the server originally set the cookie. In my case its relevant because of a mashup we are doing. The reason why few users get bitten by this issue is that indeed most servers support url encoding. So the scenario is not so obscure, only that it creates problems is. Now if we make this something the user has to do on his own, then you will have all sorts of users fall into this trap over and over again (even if you document this). But if there is a method "passBrowserCookieToServer()", then it will be clear for people that do write a proxy what method they should use to send the cookie to the server. Thanks for looking into this! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||