Drupal Custom Route Returns Access Denied? Trace the Permission Check in Order
A custom Drupal page can render correctly for an administrator and return Access denied for everyone else. The controller may be fine; Drupal often rejects the request before it calls that controller because a route requirement is missing, too narrow or based on a permission that was never granted.
Debug the route from the outside in: confirm the route is the one being matched, read every access requirement, check the permission assignment, then inspect custom access logic and cacheability. That order avoids the tempting but unsafe “make it public and see if it works” workaround.

Editorial illustration; access checks are evaluated by Drupal and the drawing is conceptual.
Summary
- A route can have multiple access requirements; inspect all of them before debugging the controller.
- Prefer a named permission for a feature, then grant it only to the roles that need it.
- Custom access checks must return correct
AccessResultvalues and cache metadata so a decision for one user is not reused incorrectly for another.
1. Confirm the request reaches the route you think it does
Start with the exact URL and the route definition in your module’s *.routing.yml file. Check the path placeholder names, route name, controller and any parameter conversion. If you changed route definitions recently, rebuild Drupal’s caches with your normal development workflow and test the same URL again.
A route can appear unavailable because a menu link is hidden, but menu visibility and route access are different concerns. A hidden menu item does not secure a route; a visible link does not grant access. Test the URL directly while signed in as the affected role.
When two modules define similar paths or alter routes dynamically, inspect the matched route rather than assuming the file you edited is active. Log or use an appropriate development tool to confirm the route name and requirements for that request. Avoid testing by setting _access: 'TRUE' on a production route: it bypasses the permission gate for every visitor.
2. Read every requirement in the route definition
Drupal route requirements are in the route’s requirements section. A basic feature permission could look like this:
example_reports.admin:
path: '/admin/reports/example'
defaults:
_controller: '\\Drupal\\example_reports\\Controller\\ReportController::build'
_title: 'Example report'
requirements:
_permission: 'view example reports'
The permission name must be defined by the module, commonly in example_reports.permissions.yml, and then granted at People → Permissions. Drupal’s routing documentation notes that requirements can include permissions, roles, entity access or custom access checkers. If multiple checks are present, they can all affect the result; do not assume that adding one permission makes the other checks disappear.
For an entity route, _entity_access: 'node.view' asks Drupal to apply entity access for the matched node. That is usually safer than writing a raw owner-ID comparison in a controller. A route that needs both a general permission and entity access should express that deliberately and be tested with accounts representing each intended case.
3. Verify the permission is defined and granted
Check the permission machine name character-for-character. A typo in YAML can leave Drupal checking a different capability than the one shown in the interface. Confirm that the permission appears on People → Permissions, then grant it to a test role rather than immediately adding it to every role.
Test at least three cases: an anonymous visitor, an authenticated user without the permission, and a user with the permission. If the page is tied to content ownership, test both the owner and a non-owner. Record the expected result for each case. This small matrix tells you whether the requirement is too strict, too broad or working as intended.
If permission changes do not appear, rebuild caches and make sure you changed the correct environment and role. On a multisite installation, confirm you are editing the intended site. Also check whether configuration deployment will overwrite your local permission assignment; configuration belongs in the workflow that manages roles and permissions for that site.
4. Inspect custom access checks and return values
A custom access checker should make the decision in an access service or a suitable entity access implementation, not by hiding the controller output after it has run. Drupal’s AccessResult type distinguishes allowed, forbidden and neutral. These values are not interchangeable: a neutral result means the checker has not granted access, not that access is allowed. When converting a result to a boolean, Drupal documents using isAllowed() rather than treating “not forbidden” as allowed.
A minimal shape for a custom check is:
use Drupal\\Core\\Access\\AccessResult;
use Drupal\\Core\\Session\\AccountInterface;
public function access(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, 'view example reports');
}
The exact method signature depends on how the access checker is registered and what route parameters it receives. Treat the snippet as a shape, not a complete service definition. If the decision depends on a node, owner, group membership or other entity, include that dependency and return an access result whose cache metadata varies with the relevant context and invalidates when the entity changes.
This is not merely a performance detail. If a user-specific access decision is cached without the appropriate cache context, Drupal can reuse a result for a different user or role. If the decision depends on content, the entity’s cache tags may also need to be carried into the result. When you are unsure which metadata applies, prefer Drupal’s established entity access mechanisms over hand-rolled comparisons.
5. Separate authorization from presentation
A common debugging shortcut is to remove the access requirement until a controller renders. That proves only that code can produce a response; it does not show that the route is safe. Restore the intended rule and test the role matrix before shipping.
Also inspect the status code and logs. A 403 usually indicates an access decision; a 404 may mean the route or entity was not found, though sites can intentionally hide inaccessible content as not found. A redirect to login can come from access handling or custom middleware. Capture the request path, account role, status code and relevant log entry so you can compare local and production behavior.
For further Drupal operations, see how to trace a Drupal Views exposed filter that returns no results and how to choose Drupal Batch API or Queue API. They address separate request and background-work paths, but the same habit applies: identify the layer that made the decision before changing configuration.
Mistakes to avoid
- Using
_access: 'TRUE'as a permanent debugging fix. - Hiding a menu item and assuming the route is protected.
- Confusing neutral with allowed in a custom checker.
- Checking only as an administrator, whose permissions can mask the issue.
- Returning a user-specific decision without its cache contexts or entity dependencies.
- Changing access rules on production before reproducing the failure on a safe environment.
My Take
For most custom pages, a clearly named permission is the simplest starting point. Add entity-level checks only when the page truly depends on a particular item. Keeping those decisions in Drupal’s access system makes them easier to test than scattering role checks through controller code.
Bottom Line
When a Drupal route returns 403, confirm the matched route, inspect every requirement, verify the permission definition and role grant, then review custom access results and cache metadata. Keep the intended boundary in place while debugging.