Problem/Motivation

When running the security review on my relatively new (started at Drupal 9.4.7) site, it fails, with this from the watchdog log:

Error: Class "Symfony\Component\Filesystem\Filesystem" not found in Drupal\security_review\Checks\PrivateFiles->run() (line 38 of /modules/contrib/security_review/src/Checks/PrivateFiles.php)

Steps to reproduce

Proposed resolution

Require the symfony/filesystem component when requiring the module with Composer, if that is the correct required component for the PrivateFiles.php check.

If the check should be using the Drupal core version, not the Symfony version that is stated, then I would think that last use line of PrivateFiles.php needs updating to:

use Drupal\Core\Component\Filesystem\Filesystem;

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

natts created an issue. See original summary.

smustgrave’s picture

Can you check your file permissions on vendor folder? Symfony\Component\Filesystem has been around from what I can tell in Drupal core for some time.

natts’s picture

Issue summary: View changes

It wasn't a permissions issue on the root vendor directory.

A version of the Filesystem class is indeed in core, but the PrivateFiles.php check in this module wants to use the Symfony version:

<?php

namespace Drupal\security_review\Checks;

use Drupal\Core\Link;
use Drupal\Core\StreamWrapper\PrivateStream;
use Drupal\security_review\Check;
use Drupal\security_review\CheckResult;
use Symfony\Component\Filesystem\Filesystem;

/**
 * Checks whether the private files' directory is under the web root.
 */
class PrivateFiles extends Check {
...

So as a workaround, I had to require the component in Composer ('composer require symfony/filesystem') to get that specific version of the class into my codebase.

If the check should be using the Drupal core version, not the Symfony version that is stated, then I would think that last use line of PrivateFiles.php needs updating to:

use Drupal\Core\Component\Filesystem\Filesystem;

natts’s picture

Issue summary: View changes

smustgrave’s picture

Status: Active » Needs review

This work for you?

natts’s picture

I wasn't the author of the Private Files check, so I don't know which is the correct version of the Filesystem class to be used by it.

  • smustgrave committed 4cec3a60 on 2.0.x
    Issue #3337726: Error: Class "Symfony\Component\Filesystem\Filesystem"...
smustgrave’s picture

Status: Needs review » Fixed

This should ensure symfony is installed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

richardmetzger’s picture

Just installed this module and ran across the reported error.

composer require symfony/filesystem

solved it for me.