Parameter "filepath" for route "system.private_file_download" must match ".+"

Created on 30 June 2023, 12 months ago
Updated 4 August 2023, 11 months ago

When using 3.0.8 inside Drupal 10 (with S3 enabled, not sure if related) I get this error:

Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "filepath" for route "system.private_file_download" must match ".+" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 203 of core/lib/Drupal/Core/Routing/UrlGenerator.php).

This can be traced back to processUserConf function inside imce/src/Imce.php

$conf['root_url'] = preg_replace('@/(?:%2E|\.)$@i', '', $url_gen->generateAbsoluteString($conf['root_uri'] . '.'));

This piece of code gets "private://" as a parameter which is not enough for the generateAbsoluteString function to work:

$url_gen->generateAbsoluteString($conf['root_uri'] . '.')

Since the route system.private_file_download inside core/modules/system/system.routing.yml
requires a path after the "private://" scheme, it fails.

Somehow this doesn't fail in D9, but it does in D10.

Temporary workaround:

    if($conf['root_uri'] == 'private://'){
      $conf['root_url'] = \Drupal::request()->getSchemeAndHttpHost().'/system/files/private%3A';
    }else{
      $conf['root_url'] = preg_replace('@/(?:%2E|\.)$@i', '', $url_gen->generateAbsoluteString($conf['root_uri'] . '.'));
    }
πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium pablovos

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

Comments & Activities

  • Issue created by @pablovos
  • πŸ‡¨πŸ‡¦Canada liquidcms

    Removed the D10 from the title as i am getting this issue with D9.5.

    I am trying to set up S3FS storage to use for private files. It seemed to be almost working except trying to read the uploaded file and i get a WSOD with the error posted here. The top of the stack trace appears to be related to S3Fs; but further down i see related to imce. Which is not related to anything i am doing as imce is not involved (this is simply a file field). But, if i try to disable IMCE the site crashes:

    drush pmu imce: Base route not available for route entity.imce_profile.edit_form

    and on the site:

    Drupal\Component\Plugin\Exception\PluginNotFoundException: The "imce_profile" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Quoting myself from πŸ’¬ Can't get S3FS installed correctly Fixed

    S3fs does 'relative path resolution' converting "private://." to "private://" because this is what a normal filesystem when working with paths. Drupal Core is a bit 'dumb' in this regard as it doesn't currently do this, though I belive this is something that may be re-considered in the future.

    Before sa-core-2023-005 it may have been arguable that S3FS module should not be resolving "scheme://." to "scheme://" however after sa-core-2023-005 public disclosure I believe it indicates we are correct in resolving the path to reduce long term risk.

    With that said even the method of changing to "scheme://.a_file_name.txt" would be a 'hack' in my opinion and IMCE really should not be depending upon the root scheme:// to determine URL's. The fact that URL resolution is a part of the hook_file_download() is another indicator raising the question is the imce_hook_file_download() possibly open to de-coupling.

    I suspect the fact IMCE does "scheme://." is because they have already encountered this fault at one time in the past or during initial development trying to do "private://" where Drupal Core itself threw the same exception.

    IMCE did work on this partly in https://www.drupal.org/project/imce/issues/3320228 β†’ however they ended up doing so only for the browser not the IMCE class, though its the same root portion of code that was initially called out as being of concern.

    • ufku β†’ committed 0dcf5862 on 3.x
      Isseu #3371499: Use a regular path for generating root url
      
  • Status changed to Fixed 11 months ago
  • Committed a patch to 3.x that uses a normal path to detect the root url.

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

Production build 0.69.0 2024