Skip to content

Commit ee79ae3

Browse files
committed
feat: filter out root package
Neither `composer show` returns, nor users of vulnerability management are interested in the root package of the application - it is an arbitrary name most likely unknown to any CVE database. Therefore the agent should not report it.
1 parent aab8068 commit ee79ae3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

agent/lib_composer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ static bool nr_execute_handle_autoload_composer_is_initialized() {
3030
return false;
3131
}
3232
#else
33-
if (NULL == nr_php_find_class_method(zce, "getallrawdata")) {
33+
if (NULL == nr_php_find_class_method(zce, "getallrawdata")
34+
|| NULL == nr_php_find_class_method(zce, "getrootpackage")) {
3435
nrl_verbosedebug(
3536
NRL_INSTRUMENT,
3637
"Composer\\InstalledVersions class found, but methods not found");
@@ -135,9 +136,13 @@ static void nr_execute_handle_autoload_composer_get_packages_information(
135136
= ""
136137
"(function() {"
137138
" try {"
139+
" $root_package = \\Composer\\InstalledVersions::getRootPackage();"
138140
" $packages = array();"
139141
" foreach (\\Composer\\InstalledVersions::getAllRawData() as $installed) { "
140142
" foreach ($installed['versions'] as $packageName => $packageData) {"
143+
" if ($packageName == @$root_package['name']) {"
144+
" continue;"
145+
" }"
141146
" if (isset($packageData['pretty_version'])) {"
142147
" $packages[$packageName] = ltrim($packageData['pretty_version'], 'v');"
143148
" }"

tests/integration/autoloader/autoload-with-composer/vendor/composer/InstalledVersions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public static function getAllRawData()
3535
return array($installed);
3636
}
3737

38+
// This Composer's runtime API method is used by the agent to get the root package:
39+
public static function getRootPackage()
40+
{
41+
$installed = require __DIR__ . '/installed.php';
42+
// This mock only returns a single dataset; in real life, there could be more
43+
return $installed[0]['root'];
44+
}
45+
3846
// Mock of 'composer show' used by integration tests to generate list of packages:
3947
public static function show() {
4048
$installed = self::getAllRawData();

0 commit comments

Comments
 (0)