Overview

This is a subset of the original scope of #3494915: Support entity-level + field-level access checking in auto-save — i.e. in `experience_builder.api.api.(layout.post|auto-save.post)`.

Currently, the access administration pages permission is hardcoded in a few places critical to loading the XB UI:

experience_builder.experience_builder:
  path: '/xb/{entity_type}/{entity}'
…
  requirements:
    _permission: 'access administration pages'

+

experience_builder.api.layout.get:
  path: '/xb/api/layout/{entity_type}/{entity}'
  defaults:
    _controller: 'Drupal\experience_builder\Controller\ApiLayoutController::get'
  requirements:
    _permission: 'access administration pages'
…

Proposed resolution

  1. Update experience_builder.experience_builder to use _entity_access
  2. Update experience_builder.api.layout.get to respect entity update/field edit access of edited XB field:
    1. entity update: use the _entity_access route requirement, which supports dynamic entity types
    2. field edit: in the ::get() method, call ::fieldAccess(operation: 'edit') — this is not available as a route requirement (plus the XB field name must first be resolved, which can kinda only happen in the controller)

User interface changes/steps to reproduce

  1. Grant the access administration pages permission to the anonymous user.
  2. As the anonymous user, access /xb/node/1/editor, which is an article node that the anonymous user cannot access.
    • Before (HEAD): it loads just fine!
    • After: 403.
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

wim leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes

wim leers credited tedbow.

wim leers’s picture

Title: [PP-1] Update `experience_builder.(experience_builder|api.layout.get) routes` to respect content entity update/field edit access of edited XB field » Update `experience_builder.(experience_builder|api.layout.get) routes` to respect content entity update/field edit access of edited XB field

Actually, this is AFAICT not blocked.

Crediting @tedbow because his comments on #3494915: Support entity-level + field-level access checking in auto-save — i.e. in `experience_builder.api.api.(layout.post|auto-save.post)` have helped me craft this. 😊

wim leers’s picture

Issue summary: View changes

deepakkm made their first commit to this issue’s fork.

deepakkm’s picture

Assigned: Unassigned » deepakkm
Status: Active » Needs work
deepakkm’s picture

Assigned: deepakkm » Unassigned
Status: Needs work » Needs review

The failing pipeline is due to the rebase done with 0.x otherwise all tests are passing.

wim leers’s picture

Status: Needs review » Needs work
deepakkm’s picture

Status: Needs work » Needs review

deepakkm changed the visibility of the branch 0.x to hidden.

deepakkm’s picture

MR !957 was messed and hence created a new MR with similar changes

jatingupta40 made their first commit to this issue’s fork.

wim leers’s picture

Priority: Normal » Critical
Status: Needs review » Needs work
Issue tags: -stable blocker +beta blocker

Based on meeting just now, can we get:

  • the failing tests to explicitly skipped on SQLite, and have a comment pointing to the relevant core issue?
  • an update to .gitlabci.yml to use MariaDB by default instead of SQLite? (Or MySQLite, whichever is fastest.)
deepakkm’s picture

The pipeline passed - https://git.drupalcode.org/issue/experience_builder-3516432/-/pipelines/..., when the work was done. but failed after a rebase done from another person and i may know why because of the major changes introduced in ApiLayoutController.

I'll update the test case for this once.

but the actual update in gitlab file goes to this issue - https://www.drupal.org/project/experience_builder/issues/3518292, where pipeline failing for 1 and passes for another , i'll update the gitlab file for that. Thanks

mglaman’s picture

It failed due to type -> component_id in the tree

mglaman’s picture

Assigned: Unassigned » deepakkm
deepakkm’s picture

Assigned: deepakkm » Unassigned
Status: Needs work » Needs review

This is now good for review. The failing pipeline in cypress test is not part of the changes done in this MR.

wim leers’s picture

Status: Needs review » Needs work

but the actual update in gitlab file goes to this issue - https://www.drupal.org/project/experience_builder/issues/3518292, where pipeline failing for 1 and passes for another , i'll update the gitlab file for that. Thanks

and

The failing pipeline in cypress test is not part of the changes done in this MR.

But … this one surely isn't introducing transliteration, so why is this one failing? 🤔 Anyway, because you really want this merge order, I tried to land #3518292: Allow searching for content in the navigator, via `/xb/api/v0/content/{entity_type}`, but couldn't: #3518292-28: Allow searching for content in the navigator, via `/xb/api/v0/content/{entity_type}`.

deepakkm’s picture

So right now there are 3 cypress tests failing and i have no idea why these tests are failing. No idea how i can move forward in fixing those. The major problem i have in setting up my cypress test is the XbSetup is throwing error.

Though looking for a way forward on this.

mglaman’s picture

Assigned: Unassigned » deepakkm

Assigning to deepakkm, had some MR review feedback

deepakkm’s picture

StatusFileSize
new356.66 KB

I have no idea now as to how to fix this random cypress failure [component-operation.cy.js] though i reran this test but it still fails and passes locally as shown in the screenshot.

deepakkm’s picture

Assigned: deepakkm » Unassigned
Status: Needs work » Needs review
mglaman’s picture

Assigned: Unassigned » mglaman

Giving it a quick look over

mglaman’s picture

Assigned: mglaman » Unassigned

Looks good to me!

penyaskito’s picture

Status: Needs review » Reviewed & tested by the community

LGTM too

penyaskito’s picture

Status: Reviewed & tested by the community » Needs work

The playwright failure looks legit though?

mglaman’s picture

Status: Needs work » Reviewed & tested by the community
$ composer config minimum-stability dev
$ composer require drupal/core-dev "drupal/experience_builder @dev" drush/drush --with-all-dependencies
In PathRepository.php line 163:
                                                                               
  The `url` supplied for the path (../experience_builder) repository does not  
   exist                                                                       
                                      

I see this as a a not-us-failure due to an experimental job. I'll move back to RTBC and someone else can decide different. Re-running the job.

wim leers’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs followup

I spotted several reductions in test coverage without an MR comment that provides guidance why. Looks like @larowlan spotted it too.

Needs follow-up for at least the component instance form route, because the meta doesn't have an issue for it yet: #3452581: [META] XB Permissions. This (IMHO) confirms the need for a route requirement access check, although that too could be deferred to that follow-up if you prefer.

Same thing for the content entity form route, but AFAICT that could trivially be added here — follow-up is fine too.

deepakkm’s picture

Status: Needs work » Needs review
larowlan’s picture

Assigned: Unassigned » wim leers
Status: Needs review » Reviewed & tested by the community

I think this is ready, assigning to Wim for a final review and possible merge.

wim leers’s picture

Title: Update `experience_builder.(experience_builder|api.layout.get) routes` to respect content entity update/field edit access of edited XB field » Update all XB routes to respect content entity update/field edit access of edited XB field
Assigned: wim leers » Unassigned
Related issues: +#3509500: In XB's preview canvas, the Breadcrumb block does not show the edited entity's path breadcrumbs

The hook_entity_field_access() implementation unfortunately contained multiple bugs … but only due to terrible DX of core's Entity + Field access! 😭 Sorry you had to wrestle through that, @deepakkm.


Per the issue summary, this was extracted from #3494915: Support entity-level + field-level access checking in auto-save — i.e. in `experience_builder.api.api.(layout.post|auto-save.post)`, ~2.5 months ago. A lot has happened since then. Including that issue having landed. The original was that this would land first, which would then allow #3494915: Support entity-level + field-level access checking in auto-save — i.e. in `experience_builder.api.api.(layout.post|auto-save.post)` to take advantage of the infra this added. I disagree respectfully with all comments #41 through #51 on that issue, because they overlooked something crucial: it would've been up to that issue to ensure the "patch" and "post" routes for editing layout (aka the component tree of an entity) respected field access. #3527156: Add test coverage for access exception in \Drupal\experience_builder\ClientDataToEntityConverter::checkPatchFieldAccess() exists, but that's about generic intra-controller field access checking across all edited fields. When possible, the controller should never be executed; access should be denied at the route access level.

So, retitling to reflect that.

And fixing that was trivial, but the fallout of test breakages was not … turns out this ended up crashing the "breadcrumb block" (because it checks the current URL, strips it path-by-path and then eventually starts hitting the new access control added here 🤪) — all because #3509500: In XB's preview canvas, the Breadcrumb block does not show the edited entity's path breadcrumbs is not yet fixed. So, worked around that by forcing the preview to always use "front page" as the breadcrumb. 🫣

wim leers’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Marking this Patch (to be ported) to signal the incompleteness. Because:

  1. The follow-up needed (as described in #32) still needs creating. → done in #35 :)
  2. This stuff was added way back when I created Pages and didn't realize XB was broken with null entity support. I think we should keep the fix for this test and in a follow up add support for null entity (new entity creation.) There may even be one.

    — @mglaman at https://git.drupalcode.org/project/experience_builder/-/merge_requests/1...

👉 multiple follow-ups still single follow-up needed 🙏😊

Feels so good to finally have this done! 😃 Thanks, @deepakkm!

  • wim leers committed b8a87d89 on 0.x authored by deepakkm
    Issue #3516432 by deepakkm, wim leers, mglaman, penyaskito, tedbow,...
wim leers’s picture

Status: Patch (to be ported) » Fixed
Issue tags: -Needs followup
wim leers’s picture

Status: Fixed » Needs work

Shoot — this caused a regression 😭 I've requeued e2e tests dozens of times today, which is how I failed to spot that these failures were legitimate 😞

The 0.x CI job for this MR landing is consistently failing on:

  1. contain-css.cy.js
  2. global-regions.cy.js

… which I only noticed after re-queuing those CI jobs multiple times too.

The latter explicitly uses the breadcrumb block (which this MR made better (out of sheer necessity to be able to add the necessary access protection to routes, so reverting is not really an option), the former probably is implicitly relying on it? 🤔 I don't see how yet though.

isholgueras’s picture

Assigned: Unassigned » isholgueras

I'll take a look

wim leers changed the visibility of the branch 3516432-unbreak-head to hidden.

wim leers’s picture

Status: Needs work » Fixed

Thanks, @isholgueras, for saving the day! ❤️

wim leers’s picture

Assigned: isholgueras » Unassigned

Status: Fixed » Closed (fixed)

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