Add hashing of the complete URL for cache entries of dist downloads for extra safety

main
Jordi Boggiano 9 years ago
parent dc695ec78d
commit 502c5431a2

@ -122,7 +122,7 @@ class FileDownloader implements DownloaderInterface
try { try {
$checksum = $package->getDistSha1Checksum(); $checksum = $package->getDistSha1Checksum();
$cacheKey = $this->getCacheKey($package); $cacheKey = $this->getCacheKey($package, $processedUrl);
// download if we don't have it in cache or the cache is invalidated // download if we don't have it in cache or the cache is invalidated
if (!$this->cache || ($checksum && $checksum !== $this->cache->sha1($cacheKey)) || !$this->cache->copyTo($cacheKey, $fileName)) { if (!$this->cache || ($checksum && $checksum !== $this->cache->sha1($cacheKey)) || !$this->cache->copyTo($cacheKey, $fileName)) {
@ -238,12 +238,14 @@ class FileDownloader implements DownloaderInterface
return $url; return $url;
} }
private function getCacheKey(PackageInterface $package) private function getCacheKey(PackageInterface $package, $processedUrl)
{ {
if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) { // we use the complete download url here to avoid conflicting entries
return $package->getName().'/'.$package->getDistReference().'.'.$package->getDistType(); // from different packages, which would potentially allow a given package
} // in a third party repo to pre-populate the cache for the same package in
// packagist for example.
$cacheKey = sha1($processedUrl);
return $package->getName().'/'.$package->getVersion().'-'.$package->getDistReference().'.'.$package->getDistType(); return $package->getName().'/'.$cacheKey.'.'.$package->getDistType();
} }
} }

Loading…
Cancel
Save