Fixed a bug where PUC might not properly whitelist the hostname used in the metadata URL if there were at least two active plugins using the same version of PUC.

This commit is contained in:
Yahnis Elsts 2020-02-13 22:14:49 +02:00
parent 28f29c940c
commit 5cdadd0369
1 changed files with 8 additions and 4 deletions

View File

@ -60,6 +60,11 @@ if ( !class_exists('Puc_v4p9_UpdateChecker', false) ):
*/
protected $lastRequestApiErrors = array();
/**
* @var string|mixed The default is 0 because parse_url() can return NULL or FALSE.
*/
protected $cachedMetadataHost = 0;
public function __construct($metadataUrl, $directoryName, $slug = null, $checkPeriod = 12, $optionName = '') {
$this->debugMode = (bool)(constant('WP_DEBUG'));
$this->metadataUrl = $metadataUrl;
@ -187,12 +192,11 @@ if ( !class_exists('Puc_v4p9_UpdateChecker', false) ):
* @return bool
*/
public function allowMetadataHost($allow, $host) {
static $metadataHost = 0; //Using 0 instead of NULL because parse_url can return NULL.
if ( $metadataHost === 0 ) {
$metadataHost = parse_url($this->metadataUrl, PHP_URL_HOST);
if ( $this->cachedMetadataHost === 0 ) {
$this->cachedMetadataHost = parse_url($this->metadataUrl, PHP_URL_HOST);
}
if ( is_string($metadataHost) && (strtolower($host) === strtolower($metadataHost)) ) {
if ( is_string($this->cachedMetadataHost) && (strtolower($host) === strtolower($this->cachedMetadataHost)) ) {
return true;
}
return $allow;