Access checking on route denied due to CacheableDependencyInterface

Created on 19 August 2020, over 4 years ago
Updated 22 July 2024, 4 months ago

Setting up a simple access checker for the first time. Getting "access denied" even if I do a simple return AccessResult::allowed();

My log says:
Path: /reviews/42/1. Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException: in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 117 of /afs/umich.edu/group/g/grahamsi/vhosts/d8/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).

It looks like it is failing this in AccessAwareRouter:

if ($access_result instanceof CacheableDependencyInterface && $request->isMethodCacheable()) {
        throw new CacheableAccessDeniedHttpException($access_result, $access_result instanceof AccessResultReasonInterface ? $access_result->getReason() : NULL);
      }

However, I do not know what this means or how to get around it. Any help is appreciated.

πŸ’¬ Support request
Status

Fixed

Version

9.0

Component
RoutingΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States dmudie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡­πŸ‡°Hong Kong VortexCentrum

    D10.0.1 (or might be 10.0.2 - I did a Composer update but Drupal is still reporting the previous version).

    I have cleared Drupal, server and local caches often.

    NO anonymous access to any pages. Access Denied.

    Path: /publications/web/front. Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException: in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 112 of [redacted]/publications/web/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).

    Line 112 says
    throw new CacheableAccessDeniedHttpException($access_result, $access_result instanceof AccessResultReasonInterface ? $access_result->getReason() : '');

    Looking at the logs, it seems that the exception report is logged for all my activity as admin, too,

    .htaccess has been replicated from another site that works. Includes "allow from all" but in any case, that can't be the problem because the site is loading, then refusing access. So it's an internal Drupal problem.

    I have not tampered with Drupal's own .htaccess because I've never needed to in the past.

    Tried No. 8 and gained anonymous access but, as the warning note says, it gave anonymous users full edit/delete control over content. So I undid that.

    Didn't try No. 9 - too many "routing.yml" files. The risk of chaos is too great.

    Given this, it appears that the issue comes down to permissions.

    Next: I still had the page open from when I tested solution #8. So I went to nodeaccess settings. Granted anonymous access to nodes of that type, went to the page and refreshed. Once more, access denied.

    One odd thing has been the frequency of "rebuild permissions" warnings.

    I've used NodeAccess since the early days of D7.

    It turns out that the solution to this problem is to uninstall NodeAccess.

    Losing the functionality I'm used to is a pain but it's better than having a website no one can enter.

    And it takes one minute instead of the seven hours I've spent looking for the solution to the original problem.

    Hope this helps others.

  • πŸ‡­πŸ‡ΊHungary karol haltenberger

    I had the same error message suddenly appear and it only took me a couple of hours to figure out that the indentation in my my route definition was off XD

  • πŸ‡©πŸ‡ͺGermany TamB

    For anyone with the Nodeaccess module: rebuilding the node permissions solved this problem for me.

    Go to /admin/reports/status and scroll down to Node Access Permissions. There is a link 'Rebuild permissions'. Click on it. Depending on how many permissions you have, it could take a few second to a few minutes.

  • πŸ‡¨πŸ‡³China hongqing

    I encountered the issue after add products to drupal commerce, it happens sometimes, I am not sure which action triggers the issues.

    Path: /. Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException: in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 115 of /www/wwwroot/xxxx/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).
    
  • πŸ‡¨πŸ‡³China hongqing

    I found this issues is closed because issue #3257541 fixed. I do no think they are the same issues. #3257541 is about the log, while the issue here is user cannot access even being granted permissions.

Production build 0.71.5 2024