Generated with the help of an LLM.

Problem/Motivation

ParamConversionEnhancer::onException() converts a ParamNotConvertedException into a NotFoundHttpException with priority 75.

  public function onException(ExceptionEvent $event) {
    $exception = $event->getThrowable();
    if ($exception instanceof ParamNotConvertedException) {
      $event->setThrowable(new NotFoundHttpException($exception->getMessage(), $exception));
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents(): array {
    $events[KernelEvents::EXCEPTION][] = ['onException', 75];
    return $events;
  }

Fast404ExceptionHtmlSubscriber runs first, with priority 200, and at that point the exception is not yet a 404, so it ignores it.
\Drupal\Core\EventSubscriber\Fast404ExceptionHtmlSubscriber::getPriority

  protected static function getPriority() {
    // A very high priority so that it can take precedent over anything else,
    // and thus be fast.
    return 200;
  }

This affects any route where the parameter is not resolved: for /sites/default/files/styles//public/x.jpg?itok=…, the fast 404 does not trigger, and the full 404 page is rendered.

Steps to reproduce

  1. Install Drupal with the Standard profile. (Fast 404 is enabled by default).
  2. Stop excluding image style paths from fast 404s, either by applying the MR from #3216687: Remove 'fast_404.excluded_paths' from system.performance.yml or by adding this override to settings.php:
    $config['system.performance']['fast_404']['exclude_paths'] = '/\/imagecache\//';
    
  3. Request an image derivative with an invalid token for an existing image style: /sites/default/files/styles/thumbnail/public/example.png?itok=invalid

    The response is the minimal fast 404 page, as expected.
  4. Request the same URL with an image style that does not exist: /sites/default/files/styles/does_not_exist/public/example.png?itok=invalid
    The response is the full themed 404 page instead of the fast 404, although the path matches fast_404.paths.

Proposed resolution

Change priority over 200 on ParamConversionEnhancer::onException

Issue fork drupal-3637097

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

eduardo morales alberti’s picture

Issue summary: View changes
eduardo morales alberti’s picture

eduardo morales alberti’s picture

Waiting for tests

eduardo morales alberti’s picture

Status: Active » Needs review

Failed test core/modules/media_library/tests/src/FunctionalJavascript/EntityReferenceWidgetTest.php core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php seems not related to the changes.