NodeRevisionDeleteForm::submitForm() has a SQL query and is not checking access on redirect

Created on 14 April 2015, about 9 years ago
Updated 8 September 2023, 10 months ago

Problem/Motivation

NodeRevisionDeleteForm::submitForm runs a check to decide whether to redirect the user to the node page(if not remaining revisions) or the revision history page. This check, however, is a hardwired SQL query which not only fails with alternate storage engines but also if the route access check is changed.

Proposed resolution

Replace SQL query with a node storage revisions count.

Use the route access check, it just makes sense not to redirect to a page which ends up access denied.

Note that at least one test executes the changed code, core/modules/file/tests/src/Functional/FileFieldRevisionTest.php

Remaining tasks

Review

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Problem/Motivation

N/A

πŸ› Bug report
Status

Fixed

Version

10.1 ✨

Component
Node systemΒ  β†’

Last updated less than a minute ago

No maintainer
Created by

πŸ‡¨πŸ‡¦Canada chx

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

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

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Moving to NW for the tests

    Did not test or review yet.

  • πŸ‡ΊπŸ‡ΈUnited States xjm
  • πŸ‡¨πŸ‡΄Colombia jidrone

    After a deeper review I think the condition mentioned on this issue was misunderstood, because the intension is to know if there are existing revisions and redirect the user accordingly, if existing revisions go to the revisions history page, if not go to the node page.

    It is also true that is needed to check if the user has access to the revisions history page, so we can take this opportunity to fix both things:

    • Check if user has access to revisions history page.
    • Replace the hardwired SQL query.

    I improved the patch to remove the database service as well, because it is not used anymore for this test.

    I'm improving the issue description and title.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¨πŸ‡΄Colombia jidrone

    I forgot to move it to NR.

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

    Shouldn't the old parameter be deprecated vs replaced? Could this cause existing sites to now break

  • πŸ‡¨πŸ‡΄Colombia jidrone
    if ($this->connection->query('SELECT COUNT(DISTINCT [vid]) FROM {node_field_revision} WHERE [nid] = :nid', [':nid' => $this->revision->id()])->fetchField() > 1) {
    

    The problem is only with this line, so I think the way to get the existing revisions to redirect the user can be just changed to use the nodeStorage:

    $this->nodeStorage->revisionIds($this->revision)

    As I did in the patch.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Removing tests as they appear to be added.

    I think the old parameter should be deprecated. If someone is overriding this form it could break for them I believe.

    Will need a simple deprecation test once that's added.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¨πŸ‡΄Colombia jidrone

    You are right, we need to deprecate the connection argument, I did so and also I started a draft change record.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks!

    Will also need a simple test case checking for the deprecation.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¨πŸ‡΄Colombia jidrone

    Added deprecation test.

  • Status changed to RTBC over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks for sticking with this. Think this is good for a committer to take a look now.

    • longwave β†’ committed 6028a1ae on 10.1.x
      Issue #2470489 by jidrone, chx, ankithashetty, smustgrave, quietone, xjm...
  • Status changed to Fixed over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Committed and pushed to 10.1.x, thanks!

    Fixed up grammar in some comments on commit:

    --- a/core/modules/node/src/Form/NodeRevisionDeleteForm.php
    +++ b/core/modules/node/src/Form/NodeRevisionDeleteForm.php
    @@ -152,11 +152,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
             '@type' => $node_type,
             '%title' => $this->revision->label(),
           ]));
    -    // Set redirect to revisions history.
    +    // Set redirect to the revisions history page.
         $route_name = 'entity.node.version_history';
         $parameters = ['node' => $this->revision->id()];
    -    // If not revisions found or user has not the access to revisions page,
    -    // then redirect to node canonical page.
    +    // If no revisions found, or the user does not have access to the revisions
    +    // page, then redirect to the canonical node page instead.
         if (!$this->accessManager->checkNamedRoute($route_name, $parameters) || count($this->nodeStorage->revisionIds($this->revision)) === 1) {
           $route_name = 'entity.node.canonical';
         }
    
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 10 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    Published the change record.

Production build 0.69.0 2024