From 39de9899a70d8351db134027dc24ed35fc629346 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 31 Aug 2022 13:07:23 +0300 Subject: [PATCH] Lock down include wrappers to avoid abuse from third parties (#11015) --- src/Composer/Autoload/AutoloadGenerator.php | 39 +++++++------------ src/Composer/Autoload/ClassLoader.php | 31 ++++++++------- .../autoload_real_files_by_dependency.php | 27 +++++-------- .../Fixtures/autoload_real_functions.php | 27 +++++-------- ...load_real_functions_with_include_paths.php | 27 +++++-------- .../Fixtures/autoload_real_target_dir.php | 27 +++++-------- 6 files changed, 69 insertions(+), 109 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 2a20265df..921ba6b6e 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -1007,9 +1007,16 @@ REGISTER_LOADER; if ($useIncludeFiles) { $file .= << \$file) { - composerRequire$suffix(\$fileIdentifier, \$file); + \$filesToLoad = \Composer\Autoload\ComposerStaticInit$suffix::\$files; + \$requireFile = static function (\$fileIdentifier, \$file) { + if (empty(\$GLOBALS['__composer_autoload_files'][\$fileIdentifier])) { + \$GLOBALS['__composer_autoload_files'][\$fileIdentifier] = true; + + require \$file; + } + }; + foreach (\$filesToLoad as \$fileIdentifier => \$file) { + (\$requireFile)(\$fileIdentifier, \$file); } @@ -1024,27 +1031,6 @@ METHOD_FOOTER; $file .= $targetDirLoader; - if ($useIncludeFiles) { - return $file . <<