|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace Packagist\WebBundle\SecurityAdvisory;
|
|
|
|
|
|
+use Packagist\WebBundle\Entity\SecurityAdvisory;
|
|
|
+
|
|
|
class RemoteSecurityAdvisory
|
|
|
{
|
|
|
/** @var string */
|
|
@@ -16,8 +18,12 @@ class RemoteSecurityAdvisory
|
|
|
private $link;
|
|
|
/** @var ?string */
|
|
|
private $cve;
|
|
|
+ /** @var \DateTime */
|
|
|
+ private $date;
|
|
|
+ /** @var string|null */
|
|
|
+ private $composerRepository;
|
|
|
|
|
|
- public function __construct(string $id, string $title, string $packageName, string $affectedVersions, string $link, $cve)
|
|
|
+ public function __construct(string $id, string $title, string $packageName, string $affectedVersions, string $link, $cve, \DateTime $date, ?string $composerRepository)
|
|
|
{
|
|
|
$this->id = $id;
|
|
|
$this->title = $title;
|
|
@@ -25,6 +31,8 @@ class RemoteSecurityAdvisory
|
|
|
$this->affectedVersions = $affectedVersions;
|
|
|
$this->link = $link;
|
|
|
$this->cve = $cve;
|
|
|
+ $this->date = $date;
|
|
|
+ $this->composerRepository = $composerRepository;
|
|
|
}
|
|
|
|
|
|
public function getId(): string
|
|
@@ -57,19 +65,62 @@ class RemoteSecurityAdvisory
|
|
|
return $this->cve;
|
|
|
}
|
|
|
|
|
|
+ public function getDate(): \DateTime
|
|
|
+ {
|
|
|
+ return $this->date;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getComposerRepository(): ?string
|
|
|
+ {
|
|
|
+ return $this->composerRepository;
|
|
|
+ }
|
|
|
+
|
|
|
public static function createFromFriendsOfPhp(string $fileNameWithPath, array $info): RemoteSecurityAdvisory
|
|
|
{
|
|
|
- $affectedVersion = implode('|', array_map(function (array $branchInfo) {
|
|
|
- return implode(',', $branchInfo['versions']);
|
|
|
- }, $info['branches']));
|
|
|
+ $date = null;
|
|
|
+ if (preg_match('#(\d{4}-\d{2}-\d{2})#', basename($fileNameWithPath), $matches)) {
|
|
|
+ $date = new \DateTime($matches[1] . ' 00:00:00');
|
|
|
+ }
|
|
|
+
|
|
|
+ $affectedVersions = [];
|
|
|
+ $lowestBranchDate = null;
|
|
|
+ foreach ($info['branches'] as $branchInfo) {
|
|
|
+ $affectedVersions[] = implode(',', $branchInfo['versions']);
|
|
|
+ if (!$date && isset($branchInfo['time']) && is_int($branchInfo['time'])) {
|
|
|
+ $branchDate = new \DateTime('@' . $branchInfo['time']);
|
|
|
+ if (!$lowestBranchDate || $branchDate < $lowestBranchDate) {
|
|
|
+ $lowestBranchDate = $branchDate;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$date) {
|
|
|
+ if ($lowestBranchDate) {
|
|
|
+ $date = $lowestBranchDate;
|
|
|
+ } else {
|
|
|
+ $date = (new \DateTime())->setTime(0, 0, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // If the value is not set then the default value is https://packagist.org
|
|
|
+ $composerRepository = SecurityAdvisory::PACKAGIST_ORG;
|
|
|
+ if (isset($info['composer-repository'])) {
|
|
|
+ if ($info['composer-repository'] === false) {
|
|
|
+ $composerRepository = null;
|
|
|
+ } else {
|
|
|
+ $composerRepository = $info['composer-repository'];
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return new RemoteSecurityAdvisory(
|
|
|
$fileNameWithPath,
|
|
|
$info['title'],
|
|
|
str_replace('composer://', '', $info['reference']),
|
|
|
- $affectedVersion,
|
|
|
+ implode('|', $affectedVersions),
|
|
|
$info['link'],
|
|
|
- $info['cve'] ?? null
|
|
|
+ $info['cve'] ?? null,
|
|
|
+ $date,
|
|
|
+ $composerRepository
|
|
|
);
|
|
|
}
|
|
|
}
|