Fix problems Vendor Hardening Plugin has with using the File Security component

Created on 5 September 2019, about 5 years ago
Updated 12 September 2023, 12 months ago

Problem/Motivation

While working toward #2982680: Add composer-ready project templates to Drupal core , we discovered that the Vendor Hardening Plugin sometimes fails to work, throwing an error:

Fatal error: Uncaught Error: Class 'Drupal\Component\FileSecurity\FileSecurity' not found in phar:///Users/ganderson/bin/composer/src/Composer/Plugin/PluginManager.php(196) : eval()'d code:245

The problem is that Composer plugins do not include the autoload.php file; instead, they dynamically create their autoload information on the fly at runtime. This allows plugin hooks to work before the autoloader is dumped. The limitation here, though, is that the plugin manager does not allow plugins to hook the dynamic autoload generation, because this would be circular. The upshot is that a plugin can only autoload classes that are located in their default location inside vendor, because the Composer Installers plugin is not given a chance to fix up any paths. Because of this, the Vendor Hardening plugin cannot find the Core File Security component, because the later is relocated to the /core directory.

Steps to reproduce:

Proposed resolution

In #3077455: Move Drupal Components out of 'core' directory , we considered fixing this by relocating the Core File Security component back to the vendor directory; however, that solution seemed too invasive to do at this time, so we are exploring potential workarounds instead.

There are two options:

  • Preferred: Put a complete copy of the File Security class in a new namespace inside the Vendor Hardening Plugin.
  • Alternate: Manually find the /core directory and require_once the File Security class.

Remaining tasks

None.

Follow-on Tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

To work around a Composer class loader limitation, the Vendor Hardening plugin now has its own copy of the file security class from drupal/core.

🐛 Bug report
Status

Fixed

Version

8.8 ⚰️

Component
Composer 

Last updated 17 days ago

No maintainer
Created by

🇺🇸United States greg.1.anderson

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024