import v1.1.0_RC2 | 2009-09-20
This commit is contained in:
@ -16,11 +16,14 @@
|
||||
* @category Zend
|
||||
* @package Zend_Http
|
||||
* @subpackage Cookie
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com/)
|
||||
* @version $Id: Cookie.php 14530 2009-03-29 14:17:14Z shahar $
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Cookie.php 17124 2009-07-26 09:46:42Z shahar $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Uri_Http
|
||||
*/
|
||||
require_once 'Zend/Uri/Http.php';
|
||||
|
||||
|
||||
@ -38,7 +41,7 @@ require_once 'Zend/Uri/Http.php';
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Http
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com/)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Http_Cookie
|
||||
@ -233,12 +236,15 @@ class Zend_Http_Cookie
|
||||
if ($this->isExpired($now)) return false;
|
||||
if ($this->isSessionCookie() && ! $matchSessionCookies) return false;
|
||||
|
||||
// Validate domain and path
|
||||
// Domain is validated using tail match, while path is validated using head match
|
||||
$domain_preg = preg_quote($this->getDomain(), "/");
|
||||
if (! preg_match("/{$domain_preg}$/", $uri->getHost())) return false;
|
||||
$path_preg = preg_quote($this->getPath(), "/");
|
||||
if (! preg_match("/^{$path_preg}/", $uri->getPath())) return false;
|
||||
// Check if the domain matches
|
||||
if (! self::matchCookieDomain($this->getDomain(), $uri->getHost())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that path matches using prefix match
|
||||
if (! self::matchCookiePath($this->getPath(), $uri->getPath())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we didn't die until now, return true.
|
||||
return true;
|
||||
@ -311,24 +317,24 @@ class Zend_Http_Cookie
|
||||
* The expiration is past Tue, 19 Jan 2038 03:14:07 UTC
|
||||
* the maximum for 32-bit signed integer. Zend_Date
|
||||
* can get around that limit.
|
||||
*
|
||||
*
|
||||
* @see Zend_Date
|
||||
*/
|
||||
require_once 'Zend/Date.php';
|
||||
|
||||
|
||||
$expireDate = new Zend_Date($v);
|
||||
$expires = $expireDate->getTimestamp();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'path':
|
||||
$path = $v;
|
||||
break;
|
||||
|
||||
|
||||
case 'domain':
|
||||
$domain = $v;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -341,4 +347,62 @@ class Zend_Http_Cookie
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a cookie's domain matches a host name.
|
||||
*
|
||||
* Used by Zend_Http_Cookie and Zend_Http_CookieJar for cookie matching
|
||||
*
|
||||
* @param string $cookieDomain
|
||||
* @param string $host
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function matchCookieDomain($cookieDomain, $host)
|
||||
{
|
||||
if (! $cookieDomain) {
|
||||
require_once 'Zend/Http/Exception.php';
|
||||
throw new Zend_Http_Exception("\$cookieDomain is expected to be a cookie domain");
|
||||
}
|
||||
|
||||
if (! $host) {
|
||||
require_once 'Zend/Http/Exception.php';
|
||||
throw new Zend_Http_Exception("\$host is expected to be a host name");
|
||||
}
|
||||
|
||||
$cookieDomain = strtolower($cookieDomain);
|
||||
$host = strtolower($host);
|
||||
|
||||
if ($cookieDomain[0] == '.') {
|
||||
$cookieDomain = substr($cookieDomain, 1);
|
||||
}
|
||||
|
||||
// Check for either exact match or suffix match
|
||||
return ($cookieDomain == $host ||
|
||||
preg_match("/\.$cookieDomain$/", $host));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a cookie's path matches a URL path
|
||||
*
|
||||
* Used by Zend_Http_Cookie and Zend_Http_CookieJar for cookie matching
|
||||
*
|
||||
* @param string $cookiePath
|
||||
* @param string $path
|
||||
* @return boolean
|
||||
*/
|
||||
public static function matchCookiePath($cookiePath, $path)
|
||||
{
|
||||
if (! $cookiePath) {
|
||||
require_once 'Zend/Http/Exception.php';
|
||||
throw new Zend_Http_Exception("\$cookiePath is expected to be a cookie path");
|
||||
}
|
||||
|
||||
if (! $path) {
|
||||
require_once 'Zend/Http/Exception.php';
|
||||
throw new Zend_Http_Exception("\$path is expected to be a host name");
|
||||
}
|
||||
|
||||
return (strpos($path, $cookiePath) === 0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user