Unpublished forum accessible to public

Created on 14 September 2023, over 1 year ago
Updated 3 March 2024, 12 months ago

Problem/Motivation

An unpublished forum/container is accessible to the public who has the 'access content' permission.

Steps to reproduce

  1. Login as an admin user who has the permission to manage forums.
  2. Go to the forum manage page. (/admin/structure/forum)
  3. Edit one of the forums. For example (/admin/structure/forum/edit/forum/5)
  4. In the edit page, unpublish this forum by untick the 'Publish' box.
  5. Save the edit page.
  6. Logout the admin user.
  7. Visit the forum landing page as an anonymous. (/forum)
  8. At this stage, the unpublished forum still visible to the public. (My site grants 'access content' permission to anonymous to allow public visiting published contents)
  9. Click the unpublished forum in that list.
  10. Now, I can access the unpublished forum as an anonymous.

Proposed resolution

Remove unpublished forums/containers from the forum landing page.
Forbid non-admin users from accessing those unpublished forums/containers.

Remaining tasks

A patch to fix this issue.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

Fix a bug that allows public to access unpublished forums and containers.

๐Ÿ› Bug report
Status

Fixed

Version

10.2 โœจ

Component

forum.module

Created by

๐Ÿ‡ฆ๐Ÿ‡บAustralia mingsong ๐Ÿ‡ฆ๐Ÿ‡บ

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

Merge Requests

Comments & Activities

  • Issue created by @mingsong
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mingsong ๐Ÿ‡ฆ๐Ÿ‡บ

    The PHPUnit test to reproduce this issue.

    The test should fail as expected.

  • last update over 1 year ago
    29,473 pass, 2 fail
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mingsong ๐Ÿ‡ฆ๐Ÿ‡บ
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10
    1. +++ b/core/modules/forum/tests/src/Functional/ForumTermAccessTest.php
      @@ -0,0 +1,115 @@
      +    // Create a unpublished forum.
      

      nit: a => an

    2. +++ b/core/modules/forum/tests/src/Functional/ForumTermAccessTest.php
      @@ -0,0 +1,115 @@
      +    $unpublished_forum_name = $this->randomMachineName(8);
      +    $edit = [
      +      'name[0][value]' => $unpublished_forum_name,
      +      'description[0][value]' => $this->randomMachineName(200),
      +      'status[value]' => 0,
      +    ];
      +    // Save a new unpublished forum.
      +    $this->drupalGet('admin/structure/forum/add/forum');
      +    $this->submitForm($edit, 'Save');
      +    $assert_session->pageTextContains('Created new forum ' . $unpublished_forum_name);
      +
      +    // Create a new published forum.
      +    $published_forum_name = $this->randomMachineName(8);
      +    $edit = [
      +      'name[0][value]' => $published_forum_name,
      +      'description[0][value]' => $this->randomMachineName(200),
      +      'status[value]' => 1,
      +    ];
      +    // Save the new published forum.
      +    $this->drupalGet('admin/structure/forum/add/forum');
      +    $this->submitForm($edit, 'Save');
      +    $assert_session->pageTextContains('Created new forum ' . $published_forum_name);
      

      Let's create these using the api, Term::create()->save()

      We're not testing the add forum UI here, we're testing access so we don't need to use the form.

    3. +++ b/core/modules/forum/tests/src/Functional/ForumTermAccessTest.php
      @@ -0,0 +1,115 @@
      +    $assert_session->statusCodeNotEquals(200);
      

      let's be specific here and use statusCodeEquals(403)

      We could have a 500 error here and the test would pass ๐Ÿ™ƒ

    4. +++ b/core/modules/forum/tests/src/Functional/ForumTermAccessTest.php
      @@ -0,0 +1,115 @@
      +  private function reloadForumByName(string $name): TermInterface {
      

      we won't need this if we use the API instead of the form to create the terms

    Nice work on the tests, now we just need the fix ๐Ÿ’ช

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mingsong ๐Ÿ‡ฆ๐Ÿ‡บ

    Thanks @Rowlands for review the test patch #2.

    1. nit: a => an

      Corrected.

    2. Let's create these using the api, Term::create()->save()

      Updated.

    3. let's be specific here and use statusCodeEquals(403)

      I thought the same. But when I checked the test from Taxonomy module, I saw this line https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/modules/tax...
      Ideally, it should return 403 instead of 404. let's use 403 for now to see if the coming fix can pass the test.

    4. we won't need this if we use the API instead of the form to create the terms.

      Removed.

    Here is the updated patch.

    Thanks again.

  • last update over 1 year ago
    29,477 pass, 2 fail
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    Test looks good, now we just need the fix, which will likely involve adding

    _entity_access: 'taxonomy_term.view'
    

    To the requirements section in the routing entry for forum.page and an access check to \Drupal\forum\Controller\ForumController::build that checks ->access('view') on each term, collects cacheability metadata from each return (return as object TRUE) and adds that to the render array.

  • Assigned to mlncn
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mlncn Minneapolis, MN, USA

    Will take a quick swing at this.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mlncn Minneapolis, MN, USA

    Sorry i looked at the cacheability metadata and turned my head inside out. Every example i looked at in core seemed not to line up in some way. The usual approach is to check access right in the query, the closest we have to that since frighteningly loadTree() does not have an access check parameter is to do it in ForumManager's getChildren with is used both for the index and forum pages, anywhere forums are listedโ€” but again no idea how to get that into cache metadata over in build the right way.

  • last update over 1 year ago
    29,677 pass
  • last update over 1 year ago
    30,456 pass, 1 fail
  • last update over 1 year ago
    Build Successful
  • last update over 1 year ago
    29,679 pass
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Appears to have failures in 11.x which it would need to be merged into first.

    FYI patches are being phased out and it's encouraged to try gitlab. It's much faster and easier for reviews.

    Thanks!

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mingsong ๐Ÿ‡ฆ๐Ÿ‡บ

    Create a MR.

    Let's go from there.

  • Pipeline finished with Success
    about 1 year ago
    #95418
  • Status changed to Needs review about 1 year ago
  • MR looks fine no failures moving to NR

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Kanchan Bhogade

    Hi
    Tested MR !6607 on Drupal version 11.x
    Applied MR Successfully...

    Followed steps from the summary for reproducing the issue.

    Test Result:
    Removed the unpublished forums from the forum landing page for anonymous users as per the proposed solution

    Attaching screenshots for references
    RTBC++

    Keeping in "Need review" for more reviews

  • Status changed to Postponed about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Forum is approved for removal. See #1898812: [policy] Deprecate forum module for removal in Drupal 11

    This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

    It will be moved to the contributed extension once the Drupal 11 branch is open.

  • Status changed to Needs review about 1 year ago
  • Drupal core is moving towards using a โ€œmainโ€ branch. As an interim step, a new 11.x branch has been opened โ†’ , as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule โ†’ and the Allowed changes during the Drupal core release cycle โ†’ .

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    Thanks @smustgrave - because of the information disclosure here I think we should keep working on this just in case we miss removing forum again

  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Hiding patches for clarity

    Applied a simple suggestion to the test method

    Ran test-only feature

    There was 1 error:
    1) Drupal\Tests\forum\Functional\ForumTermAccessTest::testForumTermAccess
    Behat\Mink\Exception\ResponseTextException: The text "z41709kq" appears in the text of this page, but it should not.
    /builds/issue/drupal-3387172/vendor/behat/mink/src/WebAssert.php:907
    /builds/issue/drupal-3387172/vendor/behat/mink/src/WebAssert.php:312
    /builds/issue/drupal-3387172/core/modules/forum/tests/src/Functional/ForumTermAccessTest.php:85
    /builds/issue/drupal-3387172/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    ERRORS!
    

    Code change of checking forum access makese sense.

    LGTM

  • Pipeline finished with Success
    about 1 year ago
    Total: 582s
    #97140
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexpott ๐Ÿ‡ช๐Ÿ‡บ๐ŸŒ

    This bug was introduced by #2981887: Add a publishing status to taxonomy terms โ†’ . the fix seems reasonable. I do wonder if status should be accounted for in \Drupal\taxonomy\TermStorage::loadTree() as that is adding the tag 'taxonomy_term_access' to it's query but afaik this is no different to nodes.

    Committed and pushed f660bb4c1e to 11.x and 9397852246 to 10.2.x. Thanks!

    • alexpott โ†’ committed 93978522 on 10.2.x
      Issue #3387172 by Mingsong, smustgrave, mlncn, Kanchan Bhogade, larowlan...
  • Status changed to Fixed about 1 year ago
    • alexpott โ†’ committed f660bb4c on 11.x
      Issue #3387172 by Mingsong, smustgrave, mlncn, Kanchan Bhogade, larowlan...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024