@@ -80,7 +80,7 @@ public function audit(IOInterface $io, RepositorySet $repoSet, array $packages,
8080
8181 // we need the CVE & remote IDs set to filter ignores correctly so if we have any matches using the optimized codepath above
8282 // and ignores are set then we need to query again the full data to make sure it can be filtered
83- if (count ( $ allAdvisories ) > 0 && $ ignoreList !== [] && $ format === self ::FORMAT_SUMMARY ) {
83+ if ($ format === self ::FORMAT_SUMMARY && $ this -> needsCompleteAdvisoryLoad ( $ allAdvisories , $ ignoreList ) ) {
8484 $ result = $ repoSet ->getMatchingSecurityAdvisories ($ packages , false , $ ignoreUnreachable );
8585 $ allAdvisories = $ result ['advisories ' ];
8686 $ unreachableRepos = array_merge ($ unreachableRepos , $ result ['unreachableRepos ' ]);
@@ -157,6 +157,35 @@ public function audit(IOInterface $io, RepositorySet $repoSet, array $packages,
157157 return $ auditBitmask ;
158158 }
159159
160+ /**
161+ * @param array<string, array<SecurityAdvisory|PartialSecurityAdvisory>> $advisories
162+ * @param array<string, string>|array<string> $ignoreList
163+ * @return bool
164+ */
165+ public function needsCompleteAdvisoryLoad (array $ advisories , array $ ignoreList ): bool
166+ {
167+ if (\count ($ advisories ) === 0 ) {
168+ return false ;
169+ }
170+
171+ // no partial advisories present
172+ if (array_all ($ advisories , static function (array $ pkgAdvisories ) {
173+ return array_all ($ pkgAdvisories , static function ($ advisory ) { return $ advisory instanceof SecurityAdvisory; });
174+ })) {
175+ return false ;
176+ }
177+
178+ if (\count ($ ignoreList ) > 0 && !\array_is_list ($ ignoreList )) {
179+ $ ignoredIds = array_keys ($ ignoreList );
180+ } else {
181+ $ ignoredIds = $ ignoreList ;
182+ }
183+
184+ return array_any ($ ignoredIds , static function ($ id ) {
185+ return !str_starts_with ($ id , 'PKSA- ' );
186+ });
187+ }
188+
160189 /**
161190 * @param array<PackageInterface> $packages
162191 * @param string[]|array<string, string> $ignoreAbandoned
@@ -304,6 +333,7 @@ private function outputAdvisoriesTable(ConsoleIO $io, array $advisories): void
304333 $ headers = [
305334 'Package ' ,
306335 'Severity ' ,
336+ 'Advisory ID ' ,
307337 'CVE ' ,
308338 'Title ' ,
309339 'URL ' ,
@@ -313,16 +343,13 @@ private function outputAdvisoriesTable(ConsoleIO $io, array $advisories): void
313343 $ row = [
314344 $ advisory ->packageName ,
315345 $ this ->getSeverity ($ advisory ),
346+ $ this ->getAdvisoryId ($ advisory ),
316347 $ this ->getCVE ($ advisory ),
317348 $ advisory ->title ,
318349 $ this ->getURL ($ advisory ),
319350 $ advisory ->affectedVersions ->getPrettyString (),
320351 $ advisory ->reportedAt ->format (DATE_ATOM ),
321352 ];
322- if ($ advisory ->cve === null ) {
323- $ headers [] = 'Advisory ID ' ;
324- $ row [] = $ advisory ->advisoryId ;
325- }
326353 if ($ advisory instanceof IgnoredSecurityAdvisory) {
327354 $ headers [] = 'Ignore reason ' ;
328355 $ row [] = $ advisory ->ignoreReason ?? 'None specified ' ;
@@ -352,10 +379,8 @@ private function outputAdvisoriesPlain(IOInterface $io, array $advisories): void
352379 }
353380 $ error [] = "Package: " .$ advisory ->packageName ;
354381 $ error [] = "Severity: " .$ this ->getSeverity ($ advisory );
382+ $ error [] = "Advisory ID: " .$ this ->getAdvisoryId ($ advisory );
355383 $ error [] = "CVE: " .$ this ->getCVE ($ advisory );
356- if ($ advisory ->cve === null ) {
357- $ error [] = "Advisory ID: " .$ advisory ->advisoryId ;
358- }
359384 $ error [] = "Title: " .OutputFormatter::escape ($ advisory ->title );
360385 $ error [] = "URL: " .$ this ->getURL ($ advisory );
361386 $ error [] = "Affected versions: " .OutputFormatter::escape ($ advisory ->affectedVersions ->getPrettyString ());
@@ -425,6 +450,15 @@ private function getSeverity(SecurityAdvisory $advisory): string
425450 return $ advisory ->severity ;
426451 }
427452
453+ private function getAdvisoryId (SecurityAdvisory $ advisory ): string
454+ {
455+ if (str_starts_with ($ advisory ->advisoryId , 'PKSA- ' )) {
456+ return '<href=https://packagist.org/security-advisories/ ' .$ advisory ->advisoryId .'> ' .$ advisory ->advisoryId .'</> ' ;
457+ }
458+
459+ return $ advisory ->advisoryId ;
460+ }
461+
428462 private function getCVE (SecurityAdvisory $ advisory ): string
429463 {
430464 if ($ advisory ->cve === null ) {
0 commit comments