Implicit access check can lead to infinite recursion.
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3258003. -->
Reported by: [natedouglas](https://www.drupal.org/user/3518344)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p><code>DeleteAllowCheck::getCurrentPageRouteName()</code> calls <code>PathValidator::getUrlIfValid()</code>, which performs access checks based on a request object. This can lead, in some situations, to the access checks being loaded and iterated through again, and thus infinite recursion, a stack overflow, etc.</p>
<p>Example stacktrace:</p>
<pre>[0x7f3842aa7200] Drupal\Core\Access\AccessManager->performCheck("entity_field_fetch.delete_allow_check", object[0x7f3842aa7260]) /var/www/cms/docroot/core/lib/Drupal/Core/Access/AccessManager.php:159 <br>[0x7f3842aa7060] Drupal\Core\Access\AccessManager->check(object[0x7f3842aa70b0], object[0x7f3842aa70c0], object[0x7f3842aa70d0], true) /var/www/cms/docroot/core/lib/Drupal/Core/Access/AccessManager.php:135 <br>[0x7f3842aa6fc0] Drupal\Core\Access\AccessManager->checkRequest(object[0x7f3842aa7010], object[0x7f3842aa7020], true) /var/www/cms/docroot/core/lib/Drupal/Core/Access/AccessManager.php:112 <br>[0x7f3842aa6f20] Drupal\Core\Routing\AccessAwareRouter->checkAccess(object[0x7f3842aa6f70]) /var/www/cms/docroot/core/lib/Drupal/Core/Routing/AccessAwareRouter.php:109 <br>[0x7f3842aa6ea0] Drupal\Core\Routing\AccessAwareRouter->matchRequest(object[0x7f3842aa6ef0]) /var/www/cms/docroot/core/lib/Drupal/Core/Routing/AccessAwareRouter.php:94 <br>[0x7f3842aa6e30] Drupal\Core\Routing\AccessAwareRouter->match("/node/41716/delete") /var/www/cms/docroot/core/lib/Drupal/Core/Routing/AccessAwareRouter.php:150 <br>[0x7f3842aa6d40] Drupal\Core\Path\PathValidator->getPathAttributes("/node/41716/delete", object[0x7f3842aa6da0], true) /var/www/cms/docroot/core/lib/Drupal/Core/Path/PathValidator.php:163 <br>[0x7f3842aa6c40] Drupal\Core\Path\PathValidator->getUrl("node/41716/delete", true) /var/www/cms/docroot/core/lib/Drupal/Core/Path/PathValidator.php:122 <br>[0x7f3842aa6bd0] Drupal\Core\Path\PathValidator->getUrlIfValid("/node/41716/delete") /var/www/cms/docroot/core/lib/Drupal/Core/Path/PathValidator.php:82 <br>[0x7f3842aa6b40] Drupal\entity_field_fetch\Access\DeleteAllowCheck->getCurrentPageRouteName() /var/www/cms/docroot/modules/contrib/entity_field_fetch/src/Access/DeleteAllowCheck.php:109 <br>[0x7f3842aa6a20] Drupal\entity_field_fetch\Access\DeleteAllowCheck->access(object[0x7f3842aa6a70], object[0x7f3842aa6a80]) /var/www/cms/docroot/modules/contrib/entity_field_fetch/src/Access/DeleteAllowCheck.php:88 <br>[0x7f3842aa69b0] call_user_func_array(array(2)[0x7f3842aa6a00], array(2)[0x7f3842aa6a10]) [internal function]<br>[0x7f3842aa68d0] Drupal\Core\Access\AccessManager->performCheck("entity_field_fetch.delete_allow_check", object[0x7f3842aa6930]) /var/www/cms/docroot/core/lib/Drupal/Core/Access/AccessManager.php:159 <br>[0x7f3842aa6730] Drupal\Core\Access\AccessManager->check(object[0x7f3842aa6780], object[0x7f3842aa6790], object[0x7f3842aa67a0], true) /var/www/cms/docroot/core/lib/Drupal/Core/Access/AccessManager.php:135 <br>[0x7f3842aa6690] Drupal\Core\Access\AccessManager->checkRequest(object[0x7f3842aa66e0], object[0x7f3842aa66f0], true) /var/www/cms/docroot/core/lib/Drupal/Core/Access/AccessManager.php:112 <br>[0x7f3842aa65f0] Drupal\Core\Routing\AccessAwareRouter->checkAccess(object[0x7f3842aa6640]) /var/www/cms/docroot/core/lib/Drupal/Core/Routing/AccessAwareRouter.php:109 <br>[0x7f3842aa6570] Drupal\Core\Routing\AccessAwareRouter->matchRequest(object[0x7f3842aa65c0]) /var/www/cms/docroot/core/lib/Drupal/Core/Routing/AccessAwareRouter.php:94 <br>[0x7f3842aa6500] Drupal\Core\Routing\AccessAwareRouter->match("/node/41716/delete") /var/www/cms/docroot/core/lib/Drupal/Core/Routing/AccessAwareRouter.php:150 <br>[0x7f3842aa6410] Drupal\Core\Path\PathValidator->getPathAttributes("/node/41716/delete", object[0x7f3842aa6470], true) /var/www/cms/docroot/core/lib/Drupal/Core/Path/PathValidator.php:163 <br>[0x7f3842aa6310] Drupal\Core\Path\PathValidator->getUrl("node/41716/delete", true) /var/www/cms/docroot/core/lib/Drupal/Core/Path/PathValidator.php:122 <br>[0x7f3842aa62a0] Drupal\Core\Path\PathValidator->getUrlIfValid("/node/41716/delete") /var/www/cms/docroot/core/lib/Drupal/Core/Path/PathValidator.php:82 <br>[0x7f3842aa6210] Drupal\entity_field_fetch\Access\DeleteAllowCheck->getCurrentPageRouteName() /var/www/cms/docroot/modules/contrib/entity_field_fetch/src/Access/DeleteAllowCheck.php:109 <br>[0x7f3842aa60f0] Drupal\entity_field_fetch\Access\DeleteAllowCheck->access(object[0x7f3842aa6140], object[0x7f3842aa6150]) /var/www/cms/docroot/modules/contrib/entity_field_fetch/src/Access/DeleteAllowCheck.php:88 <br>[0x7f3842aa6080] call_user_func_array(array(2)[0x7f3842aa60d0], array(2)[0x7f3842aa60e0]) [internal function]<br>[0x7f3842aa5fa0] Drupal\Core\Access\AccessManager->performCheck("entity_field_fetch.delete_allow_check", object[0x7f3842aa6000]) /var/www/cms/docroot/core/lib/Drupal/Core/Access/AccessManager.php:159 <br>[0x7f3842aa5e00] Drupal\Core\Access\AccessManager->check(object[0x7f3842aa5e50], object[0x7f3842aa5e60], object[0x7f3842aa5e70], true) /var/www/cms/docroot/core/lib/Drupal/Core/Access/AccessManager.php:135 <br>[0x7f3842aa5d60] Drupal\Core\Access\AccessManager->checkRequest(object[0x7f3842aa5db0], object[0x7f3842aa5dc0], true) /var/www/cms/docroot/core/lib/Drupal/Core/Access/AccessManager.php:112 <br>[0x7f3842aa5cc0] Drupal\Core\Routing\AccessAwareRouter->checkAccess(object[0x7f3842aa5d10]) /var/www/cms/docroot/core/lib/Drupal/Core/Routing/AccessAwareRouter.php:109 <br>[0x7f3842aa5c40] Drupal\Core\Routing\AccessAwareRouter->matchRequest(object[0x7f3842aa5c90]) /var/www/cms/docroot/core/lib/Drupal/Core/Routing/AccessAwareRouter.php:94 <br>[0x7f3842aa5bd0] Drupal\Core\Routing\AccessAwareRouter->match("/node/41716/delete") /var/www/cms/docroot/core/lib/Drupal/Core/Routing/AccessAwareRouter.php:150 <br>[0x7f3842aa5ae0] Drupal\Core\Path\PathValidator->getPathAttributes("/node/41716/delete", object[0x7f3842aa5b40], true) /var/www/cms/docroot/core/lib/Drupal/Core/Path/PathValidator.php:163 <br>[0x7f3842aa59e0] Drupal\Core\Path\PathValidator->getUrl("node/41716/delete", true) /var/www/cms/docroot/core/lib/Drupal/Core/Path/PathValidator.php:122 <br>[0x7f3842aa5970] Drupal\Core\Path\PathValidator->getUrlIfValid("/node/41716/delete") /var/www/cms/docroot/core/lib/Drupal/Core/Path/PathValidator.php:82 <br>[0x7f3842aa58e0] Drupal\entity_field_fetch\Access\DeleteAllowCheck->getCurrentPageRouteName() /var/www/cms/docroot/modules/contrib/entity_field_fetch/src/Access/DeleteAllowCheck.php:109 <br>[0x7f3842aa57c0] Drupal\entity_field_fetch\Access\DeleteAllowCheck->access(object[0x7f3842aa5810], object[0x7f3842aa5820]) /var/www/cms/docroot/modules/contrib/entity_field_fetch/src/Access/DeleteAllowCheck.php:88 </pre><h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>I was able to reproduce this by calling <code>/node/nid/delete</code> while logged out on a particular node. Calls while logged in succeeded, so I think there might be something about how the access checks behave with anonymous users that causes it to be problematic in that case.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Mebbe call <code>PathValidator::getUrlIfValidWithoutAccessCheck()</code>. I tested this and it resolved correctly (i.e. asked the user to log in), at least in this specific case.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3 id="summary-ui-changes">User interface changes</h3>
<h3 id="summary-api-changes">API changes</h3>
<h3 id="summary-data-model-changes">Data model changes</h3>
issue
GitLab AI Context
Project: project/entity_field_fetch
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/entity_field_fetch/-/raw/1.0.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/entity_field_fetch
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD