Problem/Motivation

ContentEntityForm::addRevisionableFormFields contains access checks that do nothing.

Both the details element and revision checks contain #access entries that check ->access('update') which is not a valid field access operation (it should be edit)

Since the operation is invalid, this access check always returns TRUE.

The details element also checked $new_revision_default, but we cannot keep that as it would hide the revision information if Create new revision was unchecked.

Proposed resolution

Remove the access checks entirely.

See #12 and #14 for reasoning.

MediaTypeForm descriptions will be fixed in #3364973: Make Add content/media default publishing option descriptions consistent

Remaining tasks

Do it.

Original report

Problem/Motivation

Node Type form says "Users with sufficient access rights will be able to override these options." and Media Type form says "Users with the "Administer media" permission will be able to override this option.". If I create a user that can edit media and nodes without the administer permissions, the option remains overridable. 🤔 I'm not sure what would be required to not have "sufficient access rights" for the Node use case, but at least the Media use case is clearly not working the way the UI makes you believe.

Steps to reproduce

  1. Install Standard
  2. Enable Media module
  3. Confirm on /admin/structure/media/manage/image that "Create new revision" is checked
  4. Give the "Content Editor" role following permissions: "Image: Create new media", "Image: Edit any media", "Access media overview", "View all media revisions", "View media", "View own unpublished media"
  5. Log in as a content editor
  6. Go to /media/add/image to create new image media entity
  7. After creating the media entity, confirm that "Create new revision" is visible, can be unchecked, and content can be saved without creating new revision
CommentFileSizeAuthor
#3 3384520-3.patch2.25 KBlauriii

Issue fork drupal-3384520

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

lauriii created an issue. See original summary.

lauriii’s picture

Status: Active » Closed (duplicate)
lauriii’s picture

Status: Closed (duplicate) » Needs review
Issue tags: +Needs tests
StatusFileSize
new2.25 KB
lauriii’s picture

lauriii’s picture

Status: Needs review » Needs work

The last submitted patch, 3: 3384520-3.patch, failed testing. View results

omkar.podey made their first commit to this issue’s fork.

wim leers’s picture

This JSON:API test coverage was written without my involvement, see #2943899: Moderation state field cannot be updated via REST, because special handling in ModerationStateFieldItemList.

The failing assertion:

      // Information disclosure prevented: when a malicious user correctly
      // guesses the current invalid value of a field, ensure a 200 is not sent
      // because this would disclose to the attacker what the current value is.
      // @see rest_test_entity_field_access()
      $response = $this->request('PATCH', $url, $request_options);
      $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nrest_test_validation: REST test validation failed\n", $response);

That is now a 403 response instead of a 422.

3 observations:

  1. Did you already step through the code starting in NodeAccessControlHandler, where access to modifying vid is being denied, to follow the trace to how this gets mapped to a 422 response? If you did, I can’t find it in this issue.
  2. That test coverage was added in #2821077: PATCHing entities validates the entire entity, also unmodified fields, so unmodified fields can throw validation errors. Did you read that issue, to try to understand why your change is causing the 403, and whether that is indeed also a sec vulnerability?
  3. Possibly something is causing a new revision to be created automatically, which then results in vid being validated, and that causes the 403?
omkar.podey’s picture

Status: Needs work » Needs review
hooroomoo’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Removing tag, reviewed and tested

berdir’s picture

Status: Reviewed & tested by the community » Needs work

Added a few comments.

Also, that the media type settings basically has the same info as node type, with the administer media permission, but media isn't fixed yet here.

One last thing, to make this issue even more fun. I'm not even 100% sure that fixing access to do what the permission says is even the right thing to do at this point. It's likely been like this for a very long time, and sites probably rely on it, because while they might to allow users to decide if a new revision should be created or not, but not things like changing the author or sticky/promoted flags and whatever else these administer permissions allow.

which I now realize is exactly what #3364973: Make Add content/media default publishing option descriptions consistent is about, it's updating the description to match how it actually works, which is IMHO fine. There's still things to fix and improve here, like the invalid field access operations, but we wouldn't actually change NodeAccessControlHandler here.

omkar.podey’s picture

Status: Needs work » Needs review
berdir’s picture

Added some new comments.

To be clear, as I said in #12, I'm not convinced that this is the right thing to do. I think the referenced issue that just fixes the docs is the better direction. If someone wants to alter access they can do so, but this is going to be a behavior change for many sites that currently rely on this being visible.

I would suggest that we extract the few unrelatd bits that make sense, like the JS fix, and then instead get the other issue in and close this as won't fix?

smustgrave’s picture

Status: Needs review » Needs work

To keep this from stalling, unless anyone has a counter argument for #14 going to move to NW for #14

acbramley’s picture

Title: "Create new revision" is overridable regardless of permissions » ContentEntityForm::addRevisionableFormFields contain invalid access checks
Issue summary: View changes

acbramley’s picture

Status: Needs work » Needs review

Rescoped based on #12 and #14

We can just remove these access() calls entirely.

acbramley’s picture

Issue summary: View changes

Refining IS with more detail.

smustgrave’s picture

Status: Needs review » Needs work

Possible to add test coverage though? Not sure if anything can be pulled from the original MR?

acbramley’s picture

Status: Needs work » Needs review

No, this is just removing invalid code.

smustgrave’s picture

If it’s causing a bug then shouldn’t we have test coverage.

acbramley’s picture

What bug is it causing?

smustgrave’s picture

Was filed as a bug, assuming it was a bad access check. So would say test coverage should be added. But I’ll leave for others to review

acbramley’s picture

The bug is that the access checks are invalid and functionally don't do anything, the issue summary is up to date with this information and the original bug report is there as well.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Code changes look fine. I guess since this does not fix an actual bug, it could be reclassified as a task, but doesn't matter too much.

  • catch committed 719659db on 11.x
    Issue #3384520 by omkar.podey, acbramley, lauriii, smustgrave, berdir,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Had to read through this a couple of times, but overall agreed this is just dead code that should be removed, we have the issue open to make whether this stuff shows configurable which would be good to land.

Committed/pushed to 11.x, thanks!

Status: Fixed » Closed (fixed)

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