External application is redirected to frontpage in maintenance mode

Created on 15 April 2022, almost 3 years ago
Updated 14 September 2024, 6 months ago

Problem/Motivation

When authorized headless consumer requests the site in maintenance mode, he gets 302 code instead of 503. Generally if it follows redirect it gets 503, but if homepage is forbidden for consumers with HTTP server/balancer configs (or just Shield module used) consumer gets 401 response code, and tries to login again, and only than gets 503 code.

Except of long chain instead of simple response, there are 2 things:
- Not all external consumers follow redirects. The redirect is logged, and then ticket is created to Drupal team, which could be really hard to understand what happened. 503 response makes it clear. Also if JSON format is requested in "_format" query param, it is lost, and consumer gets unexpected HTML answer. (text/plain is unexpected too, but it is much more readable and understandable for API consumer)
- If the consumer is frontend application and Drupal homepage is protected - it looks that user uses it, and some time he see 403 page or login form. He tries to login again just to see "server offline" screen. It really puts out some users.

Steps to reproduce

- Forbid public access to homepage with .htaccess or Shield.
- Log in to the site.
- Put site into the maintenance mode.
- Try to request any endpoint or page.

Expected:
- Consumer is notified with 503 code about site maintainance.

Actual:
- 302 and then 401/403 code is returned.

Proposed resolution

a) If the redirect is important I propose to wrap it with response format check, like HTML subscriber does to display 403/404 custom page.

b) I don't understand what benefits the redirect does (why is below). It was introduced in #1998228. Remove it, patch is below.

As far as I understand the redirect after user logout leads him to homepage to avoid 403 error if current page isn't public. But as a rule site configured to provide login block on custom 403 page or in our case (backend isn't public) shows /user/login page as 403 one. So I don't see any need to redirect the user - he can see designed 403 behavior after maintained end, but not occasionally will be moved to frontpage.

πŸ› Bug report
Status

Fixed

Version

11.0 πŸ”₯

Component
Request processingΒ  β†’

Last updated 10 days ago

No maintainer
Created by

πŸ‡§πŸ‡ΎBelarus dewalt

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡§πŸ‡ΎBelarus dewalt

    The reason is described as "If the site is offline, log out unprivileged users." but I still can't understand why we should force the logout for all users, instead of just showing the "Site is offline" message on the blank page?

    Imagine, you use public computer, and the site occasionally goes in maintenance. You need go away soon, but you have no ability to log out. As a rule typical user have no skills to clean up cookies, use guest mode in public computers, etc. In this way the next user would see your account, and could get you PI data or compromise you on this site, delete account, etc.

    The issue could be solved providing access to "Log Out" action in maintenance too, but looks like that Drupal just uses force-logout.

  • Status changed to Needs review almost 2 years ago
  • last update almost 2 years ago
    29,402 pass
  • last update almost 2 years ago
    30,335 pass
  • πŸ‡§πŸ‡ΎBelarus dewalt

    10.x patch should work for 11 branch too.

  • Status changed to RTBC almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Have to agree, not sure the redirect is needed so the change LGTM.

  • last update almost 2 years ago
    30,335 pass
  • last update almost 2 years ago
    30,335 pass
  • last update almost 2 years ago
    30,338 pass
  • last update almost 2 years ago
    30,338 pass
  • last update almost 2 years ago
    30,338 pass
  • last update almost 2 years ago
    30,338 pass
  • last update over 1 year ago
    30,341 pass
  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡«πŸ‡·France nicolas bouteille

    Hello,

    I faced this problem today.
    We have routes that are called in ajax, some of them are called every 20 seconds on some lesson page in order to save the time spent by the student on the lesson.
    In the middle of a deployment procedure, with the site under maintenance, an error was caused by this ajax route when it shouldn't have. Because there is no way the code of this ajax route could possibly cause this specific error.

    After debugging I discovered that the first time the ajax route is called, when the student is still authenticated, the homepage was returned in HTML by the ajax call. Any call after that would return a nice 503 service unavailable response. So it was the building of the homepage that was responsible for that error when calling the ajax route the first time.

    I debugged a little further and discovered the MaintenanceModeSubscriber.php of the user module that forces the log out and forces the redirect to the homepage.

    I am happy to discover that this issue exists, but I'm skeptical to see that no final decision could be made so far :/
    Personally I also believe that this redirect to the front page should not be made, and that displaying the maintenance page is enough and better.
    Even though I understand the point of "a user on a public computer that could not log out...", I also find it very frustrating to all our students that they get logged out every time we put the site under maintenance mode. So I would be in favor not to log them out anymore.

    I actually think this could be introduced as a config checkbox on the maintenance mode page : "automatically log out unprivileged users who try to access the site while in maintenance mode" (can be safer for users who logged in on a public computer and cannot log out while site is in maintenance)
    In the mean time, I think I'm going to try the patch that gets rid of the forced log out and the forced redirect to front page.

    Nicolas

  • First commit to issue fork.
  • Pipeline finished with Success
    7 months ago
    Total: 510s
    #266330
  • Status changed to Needs review 7 months ago
  • Review the patch, created MR with respective changes. Please review, moving to NR

  • Status changed to RTBC 7 months ago
  • πŸ‡«πŸ‡·France nicolas bouteille

    Thank you the patch applies cleanly on Drupal 10.3.2 and fixes the problem of the HTML of the front page being sent in response of the ajax call when the user is logged out. Now we immediately have the simple 503 service unavailable error which is what we want.

  • First commit to issue fork.
    • catch β†’ committed e5a05a48 on 10.3.x
      Issue #3275491 by dewalt, murz, pooja_sharma, avpaderno, Nicolas...
    • catch β†’ committed 2ca6fd58 on 10.4.x
      Issue #3275491 by dewalt, murz, pooja_sharma, avpaderno, Nicolas...
    • catch β†’ committed eea46883 on 11.0.x
      Issue #3275491 by dewalt, murz, pooja_sharma, avpaderno, Nicolas...
    • catch β†’ committed fa00b96e on 11.x
      Issue #3275491 by dewalt, murz, pooja_sharma, avpaderno, Nicolas...
  • πŸ‡¬πŸ‡§United Kingdom catch

    I don't think the redirect was added in #1998228: Remove hook_menu_site_status_alter() in favor of request listeners β†’ , it was moved in that issue. As far as I can tell the original redirect was added in #363580: OpenID login fails when in maintenance mode β†’ . However this has been moved around so much since then, and changed from what it used to do, that I agree it doesn't make any sense any more.

    The one situation I can see is that say you are on /user or /some/admin/path and you get logged out by maintenance mode, if you refresh the page you'll get a 403 and you might not know why. But equally, you might not know why you got redirected to the front page either.

    Committed/pushed to 11.x and backported back through to 10.3.x, thanks!

    I agree with not removing the user logout due to the public computer issue in this change because it's not necessary to fix the bug - however I think we could open a follow-up to discuss the pros/cons of removing the logout. The public computer issue is very unlikely (and any networking or site issue that's not maintenance mode could result in someone not being able to log out at a precise moment), but people being logged out in the middle of something and losing progress is not.

  • Status changed to Fixed 6 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024