Problem:
In maintenance mode, users without the permission 'access site in maintenance mode' are logged out directly after login and should be redirected to the front page. This behaviour is broken so that an error occurs:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "/" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (Line 190 in .../core/lib/Drupal/Core/Routing/RouteProvider.php).

Steps to reproduce

  • grant the permission 'access site in maintenance mode' to anonymous users
  • revoke the permission 'access site in maintenance mode' from authenticated users
  • create new user with no roles
  • turn on maintenance mode
  • login as the new user

Result
In dblog: Symfony\Component\Routing\Exception\RouteNotFoundException: Route "/" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (Line 190 in .../core/lib/Drupal/Core/Routing/RouteProvider.php).

Resolution:
In /core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php, line 61, the method $this->url() is used unneccesarily because the redirect method already invokes the url function to resolve the given route:

$event->setResponse($this->redirect($this->url('<front>')));

Therefore, this line should read:

$event->setResponse($this->redirect('<front>'));

Comments

boogiewoogieman created an issue. See original summary.

boogiewoogieman’s picture

Issue summary: View changes
cilefen’s picture

Priority: Normal » Major
Status: Active » Needs review
tr’s picture

I was able to reproduce this without first two steps of granting/revoking a permission. That is, all you have to do is:

  • create new user with no roles
  • turn on maintenance mode
  • login as the new user

The error then shows up in the dblog. The user won't see the error - it just shows up in the dblog. The user is correctly redirected to the maintenance page.

I reviewed the patch. It is correct and does solve the problem. However I think there should be a test case to prevent the problem from reoccuring.

cilefen’s picture

Priority: Major » Normal
joelstein’s picture

Same issue here and patch fixed it for me.

Anonymous’s picture

Version: 8.4.x-dev » 8.7.x-dev
Status: Needs review » Active

Fix #3001309: Replace usages of UrlGeneratorTrait in non-api classes

// Redirect to homepage.
$event->setResponse(
  new RedirectResponse(Url::fromRoute('<front>')->toString())
);
However I think there should be a test case to prevent the problem from reoccuring.

Leaving Active.

s.messaris’s picture

Status: Active » Needs work
Issue tags: +Needs tests

Since there is a patch and tests are missing, I'm adding the "needs tests" tag and changing status to "needs work".

aron.beal’s picture

Just a note on this: I think the patch is correct, but the behavior once it is fixed if no home page is provided is to redirect back to the login page immediately, with no message to the user as to what went wrong. I'm not sure if this is the correct venue for this (versus a separate issue), but I wanted to mention it.

olafkarsten’s picture

Issue is fixed with #3001309: Replace usages of UrlGeneratorTrait in non-api classes

Not sure if we really need a test here.

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.

danielveza’s picture

Status: Needs work » Postponed
Issue tags: +Bug Smash Initiative

Confirming that @olafkarsten is correct and this error has been resolved.

Tried to replicate by:

  • Installing standard
  • Creating a new user with no roles
  • Puttting the site into maintenance mode
  • Logging in with the new user
  • Checking the logs

No errors/warnings thrown. I think this can be closed. Leaving it as postponed for a second opinion.

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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.