Return a "real" Symfony 404 response object instead of mimicking it

Created on 17 May 2023, about 1 year ago
Updated 31 October 2023, 8 months ago

Problem/Motivation

Currently, in the "Search404Controller", in line 172-177, we return a mimic of a 404 page instead of a "real" symfony 404 response object:

      // Ignore this requested page ?
      if ($is_matched || $is_wildcard) {
        $build['#title'] = $this->t('Page not found');
        $build['#markup'] = $this->t('The requested page could not be found.');
        return $build;
      }

Steps to reproduce

Proposed resolution

Return a "real" symfony 404 response.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany Grevil

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

Comments & Activities

  • Issue created by @Grevil
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7 & MySQL 5.5
    last update about 1 year ago
    Waiting for branch to pass
  • @grevil opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Super cool finding @Grevil! Really like this and I think it totally makes sense!

    Anyway this might have a bunch of possible side effects, not at least for caching. Still I'm wondering why nobody else saw this before.

    TBD:

    • Manual testing
    • Write tests
    • Check if the text needs to be escaped, because its user-generated
    • Evaluate if there might be other (negative) side-effects
  • 🇩🇪Germany Grevil

    Since there are no functional tests implemented for this module yet, I'd suggest we refer to the test issue, and create the tests there, after these fixes are committed to dev (preferably to a new SemVer Version), WITHOUT creating a new release until the tests are implemented there.

    Referring to 📌 Create tests to test this modules functionality Active .

  • 🇩🇪Germany Grevil

    No need to escape the text, as "Response" strictly requires a string as the first parameter. Furthermore, it will simply get echoed on the page through "sendContent":

        /**
         * Sends content for the current web response.
         *
         * @return $this
         */
        public function sendContent(): static
        {
            echo $this->content;
    
            return $this;
        }
    

    I am not 100% sure if code can be injected through "echo", but I found the following statement on the official php echo manual:

    // Nicht-String-Ausdrücke werden in String umgewandelt, auch wenn
    // declare(strict_types=1) verwendet wird

    see https://www.php.net/manual/de/function.echo.php

    So, it should be safe? I couldn't find any further information on this. Otherwise, there shouldn't be any negative side effect, but in the end, the maintainers should decide.

  • 🇩🇪Germany Anybody Porta Westfalica

    String doesn't mean it's (not) escaped, so I think if this comes from a variable and contains javascript for example, it will be output as-is.

    So the answer is, we should have a look how Drupal handles such return values in core.

    https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Util... might be what's needed.

  • Status changed to Needs work about 1 year ago
  • 🇩🇪Germany Grevil

    Sounds good! I could find a few core implementations using "t()" or "FormattableMarkup" but they do not really fit our use case here, therefore I guess HTML::escape would definitly make sense here!

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7 & MySQL 5.5
    last update about 1 year ago
    Waiting for branch to pass
  • Status changed to Needs review about 1 year ago
  • 🇩🇪Germany Grevil

    Please review once again!

  • 🇩🇪Germany Anybody Porta Westfalica

    Perfectly fine @Grevil! As written above this now needs tests and manual testing (did you try this already?) but in general, fine!! :)

    (With tests I'd set this RTBC!)

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7 & MySQL 5.5
    last update about 1 year ago
    Waiting for branch to pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7 & MySQL 5.5
    last update about 1 year ago
    Composer error. Unable to continue.
  • 🇩🇪Germany Grevil

    Added appropriate tests.

    Since there were no Functional nor FunctionalJS tests before, the newly added Test Class revealed the following schema errors:

    Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for search404.settings with the following errors: search404.settings:search404_use_customclue variable type is boolean but applied schema class is Drupal\Core\TypedData\Plugin\DataType\StringData, search404.settings:site_404 missing schema, search404.settings:search404_ignore_language missing schema

    I will create a new issue for that.

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7 & MySQL 5.5
    last update 8 months ago
    Waiting for branch to pass
  • Status changed to RTBC 8 months ago
  • 🇮🇳India mitthukumawat

    Thanks @Gravil.
    The redirection is fine and the phpunit tests we can fix in 📌 Create tests to test this modules functionality Active as many unmerged issues are related to each others and need all fixed changes at one place for functional test cases.

  • 🇩🇪Germany Anybody Porta Westfalica

    @mitthukumawat thank you!! :) We're so happy to see activity here again! Are you planning to become co-maintainer and revive the maintainer activity here? Was very quiet recently.

  • 🇮🇳India mitthukumawat

    @Anybody, I am working closely with Maintainer on this module.

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7 & MySQL 5.5
    last update 8 months ago
    Waiting for branch to pass
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7 & MySQL 5.5
    last update 8 months ago
    Waiting for branch to pass
  • 🇩🇪Germany Anybody Porta Westfalica

    Very well done @Grevil! Merged :)

  • Status changed to Fixed 8 months ago
  • 🇩🇪Germany Anybody Porta Westfalica
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024