Do not allow drupal/core-composer-scaffold to be used by packages other than core

Created on 1 February 2023, over 1 year ago
Updated 24 March 2023, over 1 year ago

Problem/Motivation

I would think that drupal/core-composer-scaffold definitely has the potential to alter other packages. The README has a section "Altering Scaffold Files" so you can change other package scaffold files.
Also the file-mapping section doesn't seem to put any restrictions on where you can place the scaffold files so I would assume you could put them anywhere even within another package and even overwrite files in that package.
Actually in the section composer/installers it says

However, Composer and the
composer/installers plugin have a limitation that one project cannot be moved
inside of another project. Therefore, if you use composer/installers to place
Drupal modules inside the directory web/modules/contrib, then you cannot also
use composer/installers to place files such as index.php and robots.txt
into the web directory. The drupal-scaffold plugin was created to work around
this limitation.

So it definitely sounds like you can places scaffold files inside other projects
Actually drupal/core-composer-scaffold seems like such a unique plugin that I think we might need a follow-up to force sites to opt-in the ability for other packages to use this besides the known Drupal core uses. Looking at \Drupal\Composer\Plugin\Scaffold\AllowedPackages::getTopLevelAllowedPackages():

$implicit_packages = [
      'drupal/legacy-scaffold-assets',
      'drupal/core',
    ];

These are special cases but besides that you have to opt-in packages into via the allowed-packages setting. If I look at github dependents https://github.com/drupal/core-composer-scaffold/network/dependents I don't find any. So my guess is this composer plugin is not used very much at all outside of Drupal core itself. I think like composer plugins itself a plugin like this that lets other packages copy files literally anywhere seems to be incompatible with a staged update system. In 📌 Exclude unknown paths in project base: only allow vendor + web root + whatever drupal/core-composer-scaffold allows Fixed we attempted to determine where all files to be scaffolded were but because there is no API for this it involved copying a bunch of internal code. If we were able to get that list we would probably have to do more with it that just worry about files in the base project directory. For instance what if a plugin moves a scaffold file into a directory that we are excluding from the apply phase?

Steps to reproduce

Proposed resolution

Don't support drupal/core-composer-scaffold if you have set any allowed-packages since core's own use it implicitly allowed by AllowedPackages::getTopLevelAllowedPackages().

It think this would save use a ton of complexity and actually only affect a very few sites who probably have complex use cases which is not the primary target of AU at least.

Remaining tasks

Determine if we want to let sites to override this to allow allowed-packages to be set. We could have something like allow-non-core-scaffold-packages that is simply a true or false.

This could be done in a core-post-mvp follow-up.

We also might want to consider at some supporting any package if drupal/core-composer-scaffold provided a UI like getAllScaffoldfiles() that would return all files across all packages that are allowed. Without this I don't think we can support it.

📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇺🇸United States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
  • Security improvements

    It makes Drupal less vulnerable to abuse or misuse. Note, this is the preferred tag, though the Security tag has a large body of issues tagged to it. Do NOT publicly disclose security vulnerabilities; contact the security team instead. Anyone (whether security team or not) can apply this tag to security improvements that do not directly present a vulnerability e.g. hardening an API to add filtering to reduce a common mistake in contributed modules.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024