Problem/Motivation

While working on #2737719: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method, I encountered 403 responses when I expected to get 406 responses. See #2737719-41: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method and #2737719-71: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method.

Blocks can be viewed by anonymous user by default, so when a "block" REST resource is enabled, everybody can read all block configuration. The root cause is that we ended up with a very strange interpretation of the view operation on Block config entities: rather than "read/view Block config entities", it has ended up meaning "view the rendered version of this Block config entity's plugin". It made sense then, but it also means it's highly inconsistent with how entity access is supposed to work.

For all other entities "view" == "read the entity". But in this case, because "blocks" are this complex hybrid of "entity + plugin", it really means "read the entity's plugin's output".

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

None.

API changes

TBD, hopefully none.

Data model changes

TBD, hopefully none.

Comments

Wim Leers created an issue. See original summary.

dawehner’s picture

I'm wondering whether we could have different access checking depending on the format we want to render. I would argue ideally reading of block config entities via REST, would return exactly what you expect to return.

Wim Leers’s picture

I'm wondering whether we could have different access checking depending on the format we want to render.

Interesting idea :) But wouldn't that quickly become too confusing?

I would argue ideally reading of block config entities via REST, would return exactly what you expect to return.

I'm not sure what this means?

dawehner’s picture

I'm not sure what this means?

Oh well, basically repeating the previous sentence. Check the view condition for the config entity instead of taking into account the plugin itself.

Wim Leers’s picture

Problems reported with the current code in another API-first situation: #2826813: Access checks failed for entity block:views_block !, in the JSON API module.

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.

shadcn’s picture

This is happening for BlockContent entities as well. And rather scary. Everything is exposed: from uuid to revision_id ..etc.

Wim Leers’s picture

Priority: Normal » Major

Given #7, perhaps this makes sense.

Berdir’s picture

Responding to Wim's comment from that issue:

RE: #2820315: Blocks' 'view' operation is interpreted as "render on page" instead of "read this config entity" actually applying to all entity types — I can see why you'd interpret it that way, but I think that loses very important nuance. There's a key difference IMHO: nodes, comments, users, then view == "read the entity" == "render on page" (because the rendered representation is equivalent with being able to read all fields). But in the case of block entities (config entities), what's actually happening is not rendering the data stored in that entity — it's interpreting that data to render the associated block plugin in a particular place on the page. That's what makes block config entities special in this way.

As we already discussed once on IRC, I disagree with this (view == "read the entity" == "render on page" (because the rendered representation is equivalent with being able to read all fields)), as did you in this issue in comment #7/#8 :)

Content entities have plenty of layers between reading raw data and rendering an actual entity, at least 4 that can control visibility and how it is displayed:

1. Field formatters/view display configuration. Allows to control how a field is displayed and it's also very easy to hide one completely by just moving it to hidden. Entities often have internal data that is not meant to be displayed and this is the easiest way for users to do so.
2. Text formats convert e.g. embedded entities and many other things.
3. The process layer also allows to dynamically hide/show fields
4. Twig also makes it trivial to do a {{ content|without('some_field') }}.

None of that is reflected in field access. And we do offer all those API's, even I who knows that API well usually only bother with field access for fields that should only show dynamically based on access checks. And many developers probably just do checks in preprocess/twig.

All those steps can expose internal/private data. Especially since the rest module provides default configuration for node, so just by enabling rest, your site exposes all the raw data for its configurable fields on nodes to anyone. The example I also mentioned in IRC is a newspaper paywall. Those usually don't use field/node access as the user can view the node, but he'll just get a short teaser. If the site has REST enabled and you know that, it's easy to build a script to steal all their content.

So IMHO, the problem of viewing raw data vs. viewing what Drupal renders as the visual representation of that entity exists for all entities, content but also something like a view for example. As comment #7 said, all the "scary" internal data is out there in the open.

There is one thing where block is different from content entities. And that's that their raw data is usually just configuration of what should be displayed, so it's usually impossible to actually get the data you want to have displayed. For nodes, while there are plenty of issues as well, you can probably usually get something working despite all the "scary" stuff. But that doesn't mean it is not a problem.

So yes, possibly block and node require different solutions for what is technically the same problem and probably multiple issues.

I'm not sure how to solve those things. I guess a menu block should return a JSON/data representation of the menu tree for example? A block_content block the block_content entity (which then has the content-entity side of this problem)? A breadcrumb block the breadcrumb data? Maybe we need block plugin normalizers?

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.

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.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.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.

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.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.