Skip to content

Commit 30b55be

Browse files
committed
add ini setting to control use of composer api
Add new INI setting to control use of Composer's runtime API to collect package information. By default Composer API is not to be used.
1 parent e027c59 commit 30b55be

File tree

6 files changed

+57
-1
lines changed

6 files changed

+57
-1
lines changed

agent/php_execute.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,11 @@ static void nr_execute_handle_autoload(const char* filename, const size_t filena
11541154
#define AUTOLOAD_MAGIC_FILE "vendor/autoload.php"
11551155
#define AUTOLOAD_MAGIC_FILE_LEN (sizeof(AUTOLOAD_MAGIC_FILE) - 1)
11561156

1157+
if (!NRINI(vulnerability_management_composer_detection_enabled)) {
1158+
// do nothing when use of composer to collect package info is disabled
1159+
return;
1160+
}
1161+
11571162
if (NRPRG(txn)->composer_info.autoload_detected) {
11581163
// autoload already handled
11591164
return;

agent/php_newrelic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ nrinibool_t
593593
nrinibool_t
594594
vulnerability_management_package_detection_enabled; /* newrelic.vulnerability_management.package_detection.enabled
595595
*/
596+
nrinibool_t
597+
vulnerability_management_composer_detection_enabled; /* newrelic.vulnerability_management.composer_detection.enabled
598+
*/
596599

597600
#if ZEND_MODULE_API_NO < ZEND_7_4_X_API_NO
598601
/*

agent/php_nrini.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,15 @@ STD_PHP_INI_ENTRY_EX("newrelic.vulnerability_management.package_detection.enable
30913091
newrelic_globals,
30923092
nr_enabled_disabled_dh)
30933093

3094+
STD_PHP_INI_ENTRY_EX("newrelic.vulnerability_management.composer_detection.enabled",
3095+
"0",
3096+
NR_PHP_REQUEST,
3097+
nr_boolean_mh,
3098+
vulnerability_management_composer_detection_enabled,
3099+
zend_newrelic_globals,
3100+
newrelic_globals,
3101+
nr_enabled_disabled_dh)
3102+
30943103
PHP_INI_END() /* } */
30953104

30963105
void nr_php_register_ini_entries(int module_number TSRMLS_DC) {

agent/scripts/newrelic.ini.template

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,3 +1332,12 @@ newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log"
13321332
; for vulnerability management.
13331333
;
13341334
;newrelic.vulnerability_management.package_detection.enabled = true
1335+
1336+
; Setting: newrelic.vulnerability_management.composer_detection.enabled
1337+
; Type : boolean
1338+
; Scope : per-directory
1339+
; Default: false
1340+
; Info : Toggles whether the agent should try using Composer's runtime API
1341+
; to gather package detection information for vulnerability management.
1342+
;
1343+
;newrelic.vulnerability_management.composer_detection.enabled = false
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Test detection of autoloader when Composer is used and use of composer for
9+
package detection is disabled (default). Supportability metrics for
10+
Autoloader and Composer libraries metrics must not be present. Additionally,
11+
package supportability metrics and package harvest must not be present.
12+
*/
13+
14+
/*INI
15+
*/
16+
17+
/*EXPECT_PHP_PACKAGES null*/
18+
19+
/*EXPECT_METRICS_DONT_EXIST
20+
Supportability/library/Autoloader/detected
21+
Supportability/library/Composer/detected
22+
Supportability/PHP/package/vendor1/package1/1/detected
23+
Supportability/PHP/package/vendor2/package2/2/detected
24+
*/
25+
26+
/*EXPECT_TRACED_ERRORS null*/
27+
28+
require 'autoload-with-composer/vendor/autoload.php';

tests/integration/autoloader/test_autoloader_with_composer.php renamed to tests/integration/autoloader/test_autoloader_with_composer_enabled.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
/*DESCRIPTION
88
Test detection of autoloader when Composer is used. Supportability metrics for
99
Autoloader and Composer libraries should be present. Additionally, package
10-
supportability metrics should be present for each package detected.
10+
supportability metrics should be present for each package detected. Package
11+
harvest should contain all packages reported by composer.
1112
*/
1213

1314
/*INI
15+
newrelic.vulnerability_management.composer_detection.enabled=true
1416
*/
1517

1618
/*EXPECT_PHP_PACKAGES

0 commit comments

Comments
 (0)