Fix: Forward COMPOSER_AUDIT_BLOCK_INSECURE and other env vars to Composer subprocess #2749
+457
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When installing plugins via
terminus plugin:installusing PHP 8.3 and Composer 2.9.1+, the installation fails due to Composer security advisories even when the user explicitly setsCOMPOSER_AUDIT_BLOCK_INSECURE=0.The issue is that Terminus was not forwarding environment variables (specifically
COMPOSER_AUDIT_BLOCK_INSECURE) to the Composer subprocess used during plugin installation. As a result, Composer's security audit system would block installations of plugins with known security advisories in their dependencies, even when users explicitly opted out.Example Error
Solution
This PR implements environment variable forwarding in
LocalMachineHelper::getProcess()to ensure that:COMPOSER_AUDIT_BLOCK_INSECURE,COMPOSER_ALLOW_SUPERUSER,COMPOSER_MEMORY_LIMIT, etc.TERMINUS_FORWARD_ENV=VAR1,VAR2LocalMachineHelper, so it applies to plugin install, update, and any other command that uses this helperKey Changes
src/Helpers/LocalMachineHelper.php:getProcess()to forward environment variables to subprocessesgetForwardedEnvironment()method that collects and returns env vars to forwardTERMINUS_FORWARD_ENVfor additional variablesTest Infrastructure:
tests/unit_tests/TerminusTestCase.php- Base test case classtests/unit_tests/bootstrap.php- Bootstrap for unit testsphpunit.unit.xml- Separate PHPUnit config for unit testscomposer.jsonto include unit test scripts and autoload configTests:
tests/unit_tests/Plugins/PluginEnvForwardingTest.php): 5 test cases verifying env forwarding logictests/Functional/PluginManagerCommandsTest.php::testPluginInstallRespectsComposerAuditBlockInsecureEnv): End-to-end test usingterminus-build-tools-plugin(which has known security advisories)Testing
Automated Tests
Manual Validation
To validate the fix manually:
Expected Result: Plugin installation succeeds without security advisory blocking errors.
Without the fix: Installation fails with Composer security advisory errors.
Implementation Details
The fix works by:
This ensures that when Composer runs as a subprocess, it sees the same environment variables that the parent Terminus process sees, allowing users to control Composer's behavior via environment variables.
Notes
LocalMachineHelper, not just plugin installationRelated