Problem/Motivation

Currently, if a user visits /user/login which is for example excluded with ~/user/login from being redirected, but the site is using url language path prefixes then the first request that hits AnonymousLoginSubscriber with the path being "/user/login" will not get redirected, but since this url will redirect to e.g. "/nl/user/login" this second request will not be properly handled and the Anonymous Login will now initiate a redirect.

Steps to reproduce

Proposed resolution

Cut language path prefixes from the url to be checked.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon 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

hchonov created an issue. See original summary.

hchonov’s picture

Status: Active » Needs review

anton4uk made their first commit to this issue’s fork.

anton4uk’s picture

Thanks @hchonov, for the report and MR !20! This is a real problem: with URL prefixes, /uk/user/reset/… doesn't match the hard-coded user/reset/* exclusion, so password reset links in non-default languages redirect to the login page.

MR !20 strips the prefix too late, after the alias lookup, so aliased pages with a prefix never match. For example, with ~node/123 excluded, /uk/my-alias is still redirected. It also uses url.prefixes even when negotiation isn't set to path prefixes.

I pushed an alternative in 3607104-language-prefixes. It strips the prefix before the alias lookup, only when path prefix negotiation is used, and keeps the prefix in the destination. It also adds unit tests for prefixed paths.

To test: add a second language with URL prefixes and set the paths to *. As anonymous, open /uk/user/reset/1/…: it should be handled by core, not redirected to login. Then exclude an aliased node (~node/NID) and open /uk/its-alias: it should not redirect.

  • anton4uk committed 6a996e42 on 8.x-2.x
    Issue #3607104: Strip URL language prefixes before path matching
    
anton4uk’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

japerry made their first commit to this issue’s fork.

japerry’s picture

Status: Closed (fixed) » Needs review
japerry’s picture

The change merged from here and released in 8.x-2.3 has two regressions.

Patterns that include the language prefix stopped matching. In 8.x-2.2 paths were matched with their prefix, so a pattern such as fr/node/* was the way to target a prefixed path. Since 8.x-2.3 the prefix is removed before matching, so those patterns match nothing: included pages become public and excluded pages (for example ~fr/user/register) are redirected.

The prefix is also removed on multilingual sites that do not detect the language from the URL. There a path that starts with a language code is an ordinary path, and core does not remove the prefix either.

I made a new MR (MR!32) which does the following:

  • AnonymousLoginSubscriber::redirect() matches the path and alias with the language prefix as well as without it. A pattern without a prefix applies to every language, a pattern with a prefix applies to that language only.
  • getLanguagePrefixes() only returns prefixes when URL detection is enabled for a configurable language type, which is the condition core uses.
  • Added AnonymousLoginLanguagePrefixTest and unit test cases for both problems. They fail on 8.x-2.x.
  • Documented prefixed and unprefixed patterns in the README.
japerry’s picture

Priority: Normal » Critical