EditEntityFieldAccessCheck::access() receives a $account argument, but doesn't pass it to accessEditEntityField(), so it also doesn't get passed to $entity->access() and $entity->get($field_name)->access(). As a result, the access gets checked for the currently logged in user rather than the injected one. This would be a critical bug if there were a known use case for needing to check access to this route for someone other than the current user, but without such a known use case, this is just a normal task.

CommentFileSizeAuthor
#87 2266809-87.interdiff.txt2.56 KBneclimdul
#87 2266809-87.patch11.82 KBneclimdul
#85 interdiff_2266809_84-85.txt787 bytesankithashetty
#85 2266809-85.patch10.23 KBankithashetty
#84 2266809-84.patch10.11 KBneclimdul
#84 2266809-84.interdiff.txt1.78 KBneclimdul
#83 2266809-83.patch9.35 KBneclimdul
#78 2266809-78.patch10.83 KBwim leers
#78 interdiff.txt1.7 KBwim leers
#73 2266809-73.patch10.58 KBwim leers
#73 interdiff-67-73.txt1.19 KBwim leers
#67 2266809-67.patch10.78 KBsnehi
#67 interdiff.txt732 bytessnehi
#59 interdiff.txt466 bytesdinesh18
#59 2266809.59.patch11.07 KBdinesh18
#57 2266809.57.patch11.12 KBdinesh18
#57 interdiff.txt479 bytesdinesh18
#52 interdiff.txt698 bytesdinesh18
#52 2266809-52.patch11.11 KBdinesh18
#51 2884879-12.patch11.11 KBdinesh18
#51 interdiff.txt698 bytesdinesh18
#48 make-2266809-48.patch11.11 KBdinesh18
#44 make-2266809-44.patch11.07 KBkeenegan
#42 make-2266809-39.patch10.89 KBaries
#38 make-2266809-38.patch10.89 KBaries
#37 make-2266809-37.patch10.86 KBaries
#35 make-2266809-35.patch10.85 KBaries
#29 make-2266809-29.patch10.77 KBaries
#26 interdiff-15-24.txt8.08 KBswarad07
#24 make-2266809-24.patch10.63 KBswarad07
#22 2266809-22.patch10.27 KBhimanshu-dixit
#15 interdiff.txt8.17 KBwim leers
#15 2266809-15.patch10.93 KBwim leers
#14 interdiff.txt916 byteswim leers
#14 2266809-14.patch2.81 KBwim leers
#8 interdiff.txt1.13 KBwim leers
#8 2266809-8.patch2.8 KBwim leers
#7 2266809-7.patch1.72 KBwim leers
#3 2266809-3.patch2.23 KBwim leers

Comments

xjm’s picture

Component: edit.module » quickedit.module
wim leers’s picture

Status: Active » Needs review
Issue tags: -Needs tests +Quick fix
StatusFileSize
new2.23 KB

Status: Needs review » Needs work

The last submitted patch, 3: 2266809-3.patch, failed testing.

wim leers’s picture

Status: Needs work » Postponed
mgifford’s picture

Status: Postponed » Active
wim leers’s picture

Status: Active » Needs review
StatusFileSize
new1.72 KB

Rerolled.

wim leers’s picture

StatusFileSize
new2.8 KB
new1.13 KB

Oops, I lost the changes to the interface in my reroll.

Thanks @nod_ for notifying me of that in IRC.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

all good now.

The last submitted patch, 7: 2266809-7.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: 2266809-8.patch, failed testing.

The last submitted patch, 7: 2266809-7.patch, failed testing.

The last submitted patch, 8: 2266809-8.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new2.81 KB
new916 bytes

In the patch above I stupidly copied the changes from #3, without taking into account the additional parameters that this specified. Brought those back, that hugely diminishes the number of failures.

wim leers’s picture

StatusFileSize
new10.93 KB
new8.17 KB

And to pass the current user to the access check, some other things need to be updated as well.

The last submitted patch, 14: 2266809-14.patch, failed testing.

The last submitted patch, 14: 2266809-14.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Status: Needs review » Needs work
Issue tags: +Novice, +php-novice
himanshu-dixit’s picture

Status: Needs work » Needs review
StatusFileSize
new10.27 KB

Here is the patch, that i rerolled.

Status: Needs review » Needs work

The last submitted patch, 22: 2266809-22.patch, failed testing.

swarad07’s picture

Status: Needs work » Needs review
StatusFileSize
new10.63 KB
wim leers’s picture

Status: Needs review » Needs work
swarad07’s picture

StatusFileSize
new8.08 KB

Attaching interdiff between 15 and 24.

swarad07’s picture

Status: Needs work » Needs review
wim leers’s picture

Version: 8.3.x-dev » 8.4.x-dev
Status: Needs review » Needs work

#2267621: Deprecate and rename EditEntityFieldAccessCheck now that the module is named Quick Edit was only committed to 8.4.x. This issue was still on 8.3.x. The patch in #24 hence does not apply to 8.4.x.

Sorry for not noticing that sooner.

aries’s picture

Status: Needs work » Needs review
StatusFileSize
new10.77 KB

Upgraded #24 against 8.4.x.

aries’s picture

Title: Make EditEntityFieldAccessCheck::access() use the $account that's passed in » Make QuickEditEntityFieldAccessCheck::access() use the $account that's passed in
wim leers’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheck.php
@@ -22,28 +22,26 @@ class QuickEditEntityFieldAccessCheck implements AccessInterface, QuickEditEntit
+

Nit: Adding this newline is not necessary.

RTBC, because that silly nit can be fixed upon commit. Or not be fixed at all.

Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheck.php
    @@ -22,28 +22,26 @@ class QuickEditEntityFieldAccessCheck implements AccessInterface, QuickEditEntit
    -  /**
    -   * {@inheritdoc}
    -   */
    

    Why is this removed? We need some documentation - I think it shouldn't be removed.

  2. +++ b/core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheck.php
    @@ -22,28 +22,26 @@ class QuickEditEntityFieldAccessCheck implements AccessInterface, QuickEditEntit
    +  public function accessEditEntityField(EntityInterface $entity, $field_name, AccountInterface $account) {
    

    Adding a new parameter with no default is a BC break - are we sure this is ok?

  3. +++ b/core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheckInterface.php
    @@ -16,10 +17,12 @@
    +  public function accessEditEntityField(EntityInterface $entity, $field_name, AccountInterface $account);
    

    Shouldn't we implement this in a BC compatible manor and fallback to the current user and default to NULL. We can only add a required argument to an interface like this in D9.

wim leers’s picture

Two things:

  1. This is only ever called by Quick Edit. So this is only breaking BC for the likely zero contrib/custom modules that are completely swapping the default implementation.
  2. This should never have had an interface. This dates back to the days that we were adding an interface for every single thing.

Hence I'm asking: do we need to be this strict for something like this? Something that A) should have been marked @internal but isn't, and B) is extremely unlikely to be used by anything else?

Don't get me wrong: I agree with everything you said in principle. But in practice, it makes no difference.

wim leers’s picture

Briefly discussed with @alexpott in IRC. We agreed on this:

The same rules must apply to everything, to Keep It Simple, Stupid. Exceptions are really problematic and if they exist need documenting.

So, @aries, you'll need to make sure to not require the new parameter to be specified. It'll need to be optional.

aries’s picture

StatusFileSize
new10.85 KB

Sorry for the delay, let me know if I missed something.

@wim-leers: I removed the unnecessary extra line.

aries’s picture

Status: Needs work » Needs review
aries’s picture

StatusFileSize
new10.86 KB

The default value was missing in the MetadataGenerator's constructor.

- In the unit-tests, do we need to keep the test cases against the old signatures along with the new ones?
- Shall I add a @TODO to remove the default value in 8.5.x?

aries’s picture

StatusFileSize
new10.89 KB

Method documentation update - $current_user is optional.

The last submitted patch, 35: make-2266809-35.patch, failed testing.

The last submitted patch, 37: make-2266809-37.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 38: make-2266809-38.patch, failed testing.

aries’s picture

Status: Needs work » Needs review
StatusFileSize
new10.89 KB

Method MockQuickEditEntityFieldAccessCheck::accessEditEntityField() 's signature amended to match with the interface.

wim leers’s picture

Status: Needs review » Needs work

Could you provide interdiffs in the future? See https://www.drupal.org/documentation/git/interdiff.

+++ b/core/modules/quickedit/src/MetadataGenerator.php
@@ -67,7 +78,7 @@ public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
+    $access = $this->accessChecker->accessEditEntityField($entity, $field_name, $this->currentUser);

$this->currentUser might be NULL.

If that's the case, we need to retrieve the current user service from the container. Otherwise we're still breaking BC.

keenegan’s picture

Status: Needs work » Needs review
StatusFileSize
new11.07 KB

I've added this

if ($this->currentUser == NULL) {
  $this->currentUser = Drupal::currentUser();
}

before

  // Early-return if user does not have access.
  $access = $this->accessChecker->accessEditEntityField($entity, $field_name, $this->currentUser);
  if (!$access) {
    return ['access' => FALSE];
  }
wim leers’s picture

vijaycs85’s picture

Reg #43:

$this->currentUser might be NULL.

If that's the case, we need to retrieve the current user service from the container. Otherwise we're still breaking BC.

@current_user injected in the service as an argument in services.yml file. If it is empty eventually it's going to be empty in container as well. Am I missing something here?
@current_user in service.yml == Drupal::currentUser() right?

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
  1. +++ b/core/modules/quickedit/src/MetadataGenerator.php
    @@ -66,8 +78,12 @@ public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
    +    if ($this->currentUser == NULL) {
    

    Should be ===.

  2. +++ b/core/modules/quickedit/src/MetadataGenerator.php
    @@ -66,8 +78,12 @@ public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
    +      $this->currentUser = Drupal::currentUser();
    

    Should have a leading backslash.

But those are trivial fixes that can be made upon commit.

Thanks all!

dinesh18’s picture

StatusFileSize
new11.11 KB

Here is an updated Patch which fixed the comments mentioned in #47.

wim leers’s picture

@Dinesh18: Thanks, but please also upload an interdiff then. Otherwise I have to manually compare every single change. See https://www.drupal.org/documentation/git/interdiff.

dinesh18’s picture

Thanks @Wim Leers
I will provide the interdiff.

dinesh18’s picture

StatusFileSize
new698 bytes
new11.11 KB

Here is the interdiffs and the patch

dinesh18’s picture

StatusFileSize
new11.11 KB
new698 bytes

ignore comment #51. patch name written is wrong.
Here is an updated one.

wim leers’s picture

Thanks, @Dinesh18!

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/quickedit/src/MetadataGenerator.php
@@ -2,11 +2,13 @@
+use Drupal;

We normally use \Drupal instead of adding a use statement for classes in the global namespace

wim leers’s picture

Oops, I missed that. Thanks. #44 introduced that. This is why we want interdiffs!

dinesh18’s picture

Assigned: Unassigned » dinesh18
dinesh18’s picture

Status: Needs work » Needs review
StatusFileSize
new479 bytes
new11.12 KB

Here is an updated patch and interdiff which implements #54

wim leers’s picture

Status: Needs review » Needs work

Sorry for not being more clear: we don't need that line! Can you just remove it altogether? Thanks :)

dinesh18’s picture

StatusFileSize
new11.07 KB
new466 bytes

No issues. I am new to Drupal 8. By the way #54 states clearly that we should not use \Drupal instead we should use it as a global namespace. Hope I am correct :)
Here is an updated patch with interdiff

dinesh18’s picture

Status: Needs work » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Perfect, thank you!

larowlan’s picture

Updating issue credit, giving @alexpott credit for picking up the BC break and @vijaycs85 for picking up the question in #46

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/editor/tests/src/Kernel/QuickEditIntegrationTest.php
index 3d7d934378..d4830b4d39 100644
--- a/core/modules/quickedit/quickedit.services.yml

+++ b/core/modules/quickedit/src/MetadataGenerator.php
@@ -66,8 +77,12 @@ public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
+    if ($this->currentUser === NULL) {
+      $this->currentUser = \Drupal::currentUser();
+    }

I agree with @vijaycs85 in #46- in what circumstances would this be NULL?

wim leers’s picture

Status: Needs review » Needs work

#63:

  1. +++ b/core/modules/quickedit/src/MetadataGenerator.php
    @@ -43,11 +51,14 @@ class MetadataGenerator implements MetadataGeneratorInterface {
    +   * @param \Drupal\Core\Session\AccountInterface $current_user
    +   *   (optional) The current user.
    
    +++ b/core/modules/quickedit/tests/modules/src/MockQuickEditEntityFieldAccessCheck.php
    @@ -13,7 +14,7 @@ class MockQuickEditEntityFieldAccessCheck implements QuickEditEntityFieldAccessC
    -  public function accessEditEntityField(EntityInterface $entity, $field_name) {
    +  public function accessEditEntityField(EntityInterface $entity, $field_name, AccountInterface $account = NULL) {
    

    Because this is an optional new parameter. And therefore subclasses may not yet have.

  2. +++ b/core/modules/quickedit/src/MetadataGenerator.php
    @@ -66,8 +77,12 @@ public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
    +    if ($this->currentUser === NULL) {
    +      $this->currentUser = \Drupal::currentUser();
    +    }
    +
         // Early-return if user does not have access.
    -    $access = $this->accessChecker->accessEditEntityField($entity, $field_name);
    +    $access = $this->accessChecker->accessEditEntityField($entity, $field_name, $this->currentUser);
    

    OTOH, this is just ensuring there is a currentUser service to pass to ::accessEditEntityField() which itself already allows NULL to be passed for similar BC reasons.

    So I agree that this if-test is pointless and can be removed.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ivan berezhnov’s picture

Issue tags: +CSKyiv18
snehi’s picture

Status: Needs work » Needs review
StatusFileSize
new732 bytes
new10.78 KB

As suggested by Wim and larowlan, removing if test.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
snehi’s picture

Thanks Wim :)

wim leers’s picture

Thank you, @snehi! :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheck.php
@@ -22,26 +22,26 @@ class QuickEditEntityFieldAccessCheck implements AccessInterface, QuickEditEntit
-   *   The currently logged in account.
+   *   (optional) The user for which to check access.
...
-  public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account) {
+  public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account = NULL) {

I don't understand why the argument here is becoming optional? This seems to have occurred in #35 as a result of mine & @Wim Leers comments in #32, #33, #34 - but I was referring to the new param on accessEditEntityField() not the existing param on access().

@Wim Leers what do you think?

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Version: 8.6.x-dev » 8.5.x-dev
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.19 KB
new10.58 KB

Indeed, #35 introduced that, without an interdiff, and I failed to spot it. My bad :( You're right of course. Fixed.

Re-reviewed the entire patch now. One question for a core committer:

+++ b/core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheckInterface.php
@@ -16,10 +17,12 @@
+   * @param \Drupal\Core\Session\AccountInterface $account
+   *   (optional) The user for which to check access.
...
-  public function accessEditEntityField(EntityInterface $entity, $field_name);
+  public function accessEditEntityField(EntityInterface $entity, $field_name, AccountInterface $account = NULL);

This needs to become non-optional in the future. How do we communicate that?

alexpott’s picture

Re #73 the best way would be to do something like this:

public function accessEditEntityField(EntityInterface $entity, $field_name, AccountInterface $account = NULL) {
  if (!$account) {
     @trigger_error('The $account parameter will be required in Drupal 9 etc...', E_USER_DEPRECATED);
  }
}

And add a legacy test for this. Doing this means that when we come to clean up the @trigger_errors in 9.x.x we'll be reminded to do this. This is only a good idea if we always pass the $account in in HEAD.

wim leers’s picture

#74… except that this is an interface. So alternative implementations will actually not be made aware.

We should deprecate \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface. There is no valid reason to ever override the default implementation, hence there is no valid reason for that interface to exist. You should be able to implement arbitrary access logic via the Entity Access API and/or Field Access API.

Once that interface is gone, #74 would work.

In other words: do what #74 says, but also deprecate that interface.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Agreed let's deprecate the interface (and also mark it @internal since we're not replacing it?).

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Version: 8.6.x-dev » 8.8.x-dev
Assigned: dinesh18 » Unassigned
Status: Needs work » Needs review
Issue tags: -Quick fix, -Novice, -php-novice +Drupal 9, +@deprecated
StatusFileSize
new1.7 KB
new10.83 KB

By now we have much more experience with evolving existing APIs while retaining BC. When #74, #75 and #76 were written that was still kind of treading new ground, not anymore today! So let's get this done :)

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

neclimdul’s picture

StatusFileSize
new9.35 KB
neclimdul’s picture

StatusFileSize
new1.78 KB
new10.11 KB

ah, that's an easy fix.

ankithashetty’s picture

StatusFileSize
new10.23 KB
new787 bytes

Tried to fix custom command failure errors in #84, thanks!

Status: Needs review » Needs work

The last submitted patch, 85: 2266809-85.patch, failed testing. View results

neclimdul’s picture

Status: Needs work » Needs review
StatusFileSize
new11.82 KB
new2.56 KB

Yeah, those errors are my fault. Tried a new way of merging patch failures and I messed it up.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

spokje’s picture

Project: Drupal core » Quick Edit
Version: 9.4.x-dev » 1.0.x-dev
Component: quickedit.module » Code

Due to Quickedit being moved out of Drupal Core and into a Contrib Module, moving this issue to the Contrib Module queue.