Issues

ZF-1629: The cookie path has some problem in Zend_Http_CookieJar

Issue Type: Bug Created: 2007-06-26T08:26:08.000+0000 Last Updated: 2009-11-17T22:58:03.000+0000 Status: Resolved Fix version(s): - 1.9.0 (31/Jul/09)

Reporter: Anhui Lin (anhuilin) Assignee: Shahar Evron (shahar) Tags: - Zend_Http_CookieJar

Related issues: Attachments:

Description

If using $path="/a/b/",the cookie which exsits in the path "/a/b/" will be filtered. for example:

<pre class="highlight">
<?php
        require_once('Zend/Http/Client.php');
        require_once('Zend/Http/CookieJar.php');

        $params=array('continue'=>'<a href="https://www.google.com/a/yourdomain.com/Dashboard">https://google.com/a/yourdomain.com/…</a>',
            'service'=>'CPanel',
            'persistent'=>'true',
            'at'=>'null',
            'userName'=>'admin',
            'password'=>'****'          
                );
        $client=new Zend_Http_Client();
        $client->setCookieJar();
 
        $client->setUri('<a href="https://www.google.com/a/yourdomain.com/LoginAction">https://google.com/a/yourdomain.com/…</a>');
        $client->setParameterPost($params);
        $client->request('POST'); 

The example can not send correct Cookie.The cookie in path of "a/yourdomain.com/LoginAction/" will be lost. if i fixed Zend_Http_Cookiejar using this codes as follows:

<pre class="highlight">
protected function _matchPath($domains, $path) {
        $ret = array();
        
        foreach ($domains as $dom => $paths_array) {
            foreach (array_keys($paths_array) as $cpath) {
                $regex = "|^" . preg_quote($cpath, "|") . "|i";
                if (preg_match($regex, $path."/") {  //I changed the line
                    if (! isset($ret[$dom])) $ret[$dom] = array();
                    $ret[$dom][$cpath] = &$paths_array[$cpath];
                }
            }
        }
        
        return $ret;
    }

The example will return right result.

Comments

Posted by Bill Karwin (bkarwin) on 2007-06-27T10:36:24.000+0000

Assigned to Shahar.

Posted by Shahar Evron (shahar) on 2007-06-27T10:55:38.000+0000

Thanks for the report - should be fixed in r. 5460 + unit tests added.

Posted by Anhui Lin (anhuilin) on 2007-06-28T09:00:19.000+0000

Hello, Shahar Evron

       The bug exist in the method of getCookie(). 

Posted by Shahar Evron (shahar) on 2007-06-28T09:33:42.000+0000

HI,

Can you attach some reproduction code?

Posted by Anhui Lin (anhuilin) on 2007-06-28T10:18:14.000+0000

Hi, This is the code.

<pre class="highlight">
<?php
        require_once('Zend/Http/Client.php');
        require_once('Zend/Http/CookieJar.php');

        $params=array('continue'=>'<a href="https://www.google.com/a/yourdomain.com/Dashboard">https://google.com/a/yourdomain.com/…</a>',
            'service'=>'CPanel',
            'persistent'=>'true',
            'at'=>'null',
            'userName'=>'admin',
            'password'=>'****'          
                );
        $client=new Zend_Http_Client();
        $client->setCookieJar();
 
        $client->setUri('<a href="https://www.google.com/a/yourdomain.com/LoginAction">https://google.com/a/yourdomain.com/…</a>');
        $client->setParameterPost($params);
        $client->request('POST');

        $jar=$client->getCookieJar();
        $cpat=$jar->getCookie('<a href="https://www.google.com/a/cpanel/yourdomain.com/Dashboard','CP_AT">https://google.com/a/cpanel/…</a>');
        $at=$cpat->getValue();

The example will get wrong result. But I changed the code as follows:

<pre class="highlight">
 public function getCookie($uri, $cookie_name, $ret_as = self::COOKIE_OBJECT)
    {
        if (is_string($uri)) {
            $uri = Zend_Uri::factory($uri);
        }
        
        if (! $uri instanceof Zend_Uri_Http) {
            throw new Zend_Http_Exception('Invalid URI specified');
        }
        
        // Get correct cookie path
        $path = $uri->getPath();
        $path = substr($path, 0, strrpos($path, '/'))."/";//The line was changed
        if (! $path) $path = '/';
        
        if (isset($this->cookies[$uri->getHost()][$path][$cookie_name])) {
            $cookie = $this->cookies[$uri->getHost()][$path][$cookie_name];
            
            switch ($ret_as) {
                case self::COOKIE_OBJECT:
                    return $cookie;
                    break;
                    
                case self::COOKIE_STRING_ARRAY:
                case self::COOKIE_STRING_CONCAT:
                    return $cookie->__toString();
                    break;
                    
                default:
                    throw new Zend_Http_Exception("Invalid value passed for \$ret_as: {$ret_as}");
                    break;
            }
        } else {
            return false;
        }
    }        

The result will be right. Can you give me Email?Thanks!

Posted by Darby Felton (darby) on 2007-07-30T09:28:33.000+0000

Fix version after 1.0.1.

Posted by Shahar Evron (shahar) on 2009-07-25T14:14:11.000+0000

Hallelujah - after 2 years, fixed in rev. 17079

Thanks!

Posted by Satoru Yoshida (satoruyoshida) on 2009-11-17T22:58:03.000+0000

I set fix version. I find this at SVN r17118 in 1.9 branch.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts