Problem/Motivation
I'm running into a strange issue where I can't access the /user/login page on an inactive domain even though /user/login is whitelisted at /admin/config/domain/settings. I always get redirected to the default domain's login page.
I dug into the code a little bit and set a breakpoint in Drupal\domain\Access\DomainAccessCheck::checkPath().
public function checkPath($path) {
$allowed_paths = $this->configFactory->get('domain.settings')->get('login_paths');
return !$this->pathMatcher->matchPath($path, $allowed_paths); // BREAKPOINT HERE
}
Interestingly, I found that $path, which is the result of Symfony\Component\Routing\Route::getPath(), seems to always return a path without the preceding "/", e.g it returns user/login rather than /user/login. I thought I might've misconfigured, but I checked domain's default configuration, and it sets the user login and password reset paths with the preceding slash, i.e. I'm using the default configuration.
No problem, though, it's simple enough to fix, so I updated my configuration to use user/login without the preceding slash. Surprisingly, this still doesn't work! However, now, instead of being redirected to the default domain's login page, I see "You're not authorized...", i.e. a 403, and I remain at the url for my inactive domain's user login page. Bizarre!
Out of curiosity, I tried whitelisting /user/login and user/login and, amazingly, I can access the /user/login form fine and login with no problems. It seems that I can only access any of these paths after whitelisting it with and without the preceding slash.
Steps to reproduce
- Create a default domain
- Create another domain, e.g. other.example.com, but set it as inactive
- Attempt to access other.exmaple/com/user/login
I'm using Domain 8.x-1.0-beta2 with Drupal 8.9.x.
Proposed Resolution
No clue.
Issue fork domain-3176457
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
sonfdComment #3
agentrickardThat's odd. We account for this logic in domain/tests/src/Functional/DomainInactiveTest.php
Perhaps that test is wrong, because a redirect would return a 200 -- though that seems wrong from a testing standpoint, the test runner should return 301 or 302.
Here's the relevant part of the test:
I wonder if any of your server parameters matter here, too?
Comment #4
agentrickardIt would be helpful if you could run that test on your system.
Comment #5
agentrickardComment #6
agentrickardComment #7
ded commentedI have run into the same issue with 2.0.0-beta2. I changed the whitelisted paths to not start with a slash so
and then they were accessible.
Comment #10
mably commentedHi @sonfd @ded, could you give a try to this issue's MR please?
Remember that if you're on a multilang site using language prefixes, you might have to add the following to the list of allowed paths:
If somebody knows why this slash trimming was done in the first place, don't hesitate to tell us why. Related commit.
Comment #11
mably commentedComment #12
mably commentedI confirm that this fix should be merged: the functional tests were not working correctly. They have been fixed.
$this->assertSession()->statusCodeEquals(200);Has been replaced by:
$this->assertEquals($url, $this->getUrl());The first assertion above was always true, even after a redirection had occurred.
Please review.
Comment #13
ben.hamelin@mably Did a quick code review, everything looked good.
Patch applied to 2.x-dev.
Confirmed with inactive domain that I could load the /user/login page.
I think this is ready to go.
Comment #14
mably commentedThanks @ben.hamelin!
Comment #16
mably commented