Issue Bug Closed

#100215Redirect by redirectMode "refererDomains" is broken

Torben Hansen 03/18/23, 18:15 updated 07/09/24, 12:46

Description

The redirect by refererDomains is broken since 2019, because:

1) The first regex only checks for non-SSL domains – see: preg_match('#^http://([[:alnum:]._-]+)/#', $url, $match)
2) The second regex is wrong (exception: Unknown modifier '/') – see: preg_match('/(?:^|\\.)' . $domain . '$/', $redirectDomain)

Reviews 3

History 714

  1. Torben Hansen changed description 03/18/23, 18:25

  2. Torben Hansen changed Related to #98372 03/20/23, 17:32

  3. Ayke Halder commented 04/27/23, 14:21

    I can confirm this.

    Environment:

    • TYPO3 multi-site instance – with domains active in current environment (e.g Development)
    • domain-a.ddev.site
    • domain-b.ddev.site
    • domain-aXddev.site (any character replaces the dot)

    All cases are only redirecting in the process of a successfull login. So no open redirect here.

    To reproduce:

    1. Always log out frontend user first.
    2. Open case URL.
    3. Login frontend user.
    4. Check the redirect result.

    Issue A: Domain-filter only active for http:// and ignored for httpS://

    Systems: TYPO3 10, 11 (12?)

    Setting “domains” ( https://docs.typo3.org/c/typo3/cms-felogin/11.5/en-us/Configuration/Index.html#domains )
    plugin.tx_felogin_login.settings.domains = domain-a.ddev.site

    … used with redirectMode = refererDomains ( https://docs.typo3.org/c/typo3/cms-felogin/11.5/en-us/Configuration/Index.html#redirectmode )
    plugin.tx_felogin_login.settings.redirectMode = refererDomains

    Case A.1

    Case A.1-http: same domain
    URL: https://domain-a.ddev.site/login/?referer=http://domain-a.ddev.site/another-page/
    Result after successful login: Redirect to http://domain-a.ddev.site/another-page/
    —> works correctly.

    Case A.1-https: same domain
    URL: https://domain-a.ddev.site/login/?referer=https://domain-a.ddev.site/another-page/
    Result after successful login: Redirect to https://domain-a.ddev.site/another-page/
    —> works somehow correctly. – Actually the domain filter is inactive here, but no issue as the domain is okay in this case.

    Case A.2

    Case A.2-http: foreign domain
    URL: https://domain-a.ddev.site/login/?referer=http://foreign-domain.org/
    Result after successful login: No redirect – domain not in environment.
    —> works correctly.

    Case A.2-https: foreign domain
    URL: https://domain-a.ddev.site/login/?referer=https://foreign-domain.org/
    Result after successful login: No redirect – domain is not in environment.
    —> works correctly.

    For implementation of the check “url is in enivronment” see Issue B in this mail.

    Case A.3

    Case A.3-http: multi-site another domain
    URL: https://domain-a.ddev.site/login/?referer=http://domain-b.ddev.site/
    Result after successful login: No redirect – domain not in plugin.tx_felogin_login.settings.domains
    —> works correctly.

    Case A.3-https: multi-site another domain
    URL: https://domain-a.ddev.site/login/?referer=https://domain-b.ddev.site/
    Result after successful login: Redirects to https://domain-b.ddev.site/
    —> failure!

    Wrong check in felogin/Classes/Redirect/RedirectModeHandler.php
    https://github.com/TYPO3-CMS/felogin/blob/bd998d7b5c2f554591daf3b83a9fe82b6eca2458/Classes/Redirect/RedirectModeHandler.php#L128

    Is:
    if (preg_match(‘#^http://([[:alnum:]._-]+)/#’, $url, $match)) {

    Must be:
    if (preg_match(‘#^https?://([[:alnum:]._-]+)/#’, $url, $match)) {

    Better be:
    if (preg_match(‘#^https?://([[:alnum:].-]+)/#’, $url, $match)) {

    – There are no underscore characters in a hostname – only in domain names underscores are allowed. –

    Case A.4

    Case A.4-http: multi-site another domain with character/dash in place of dot
    URL: https://domain-a.ddev.site/login/?referer=http://domain-aXddev.site/
    Result after successful login: Redirects to http://domain-aXddev.site/
    —> failure!

    Case A.4-https: multi-site another domain with character/dash in place of dot
    URL: https://domain-a.ddev.site/login/?referer=https://domain-aXddev.site/
    Result after successful login: Redirects to https://domain-aXddev.site/
    —> failure!

    Wrong regex construction in felogin/Classes/Redirect/RedirectModeHandler.php
    https://github.com/TYPO3-CMS/felogin/blob/bd998d7b5c2f554591daf3b83a9fe82b6eca2458/Classes/Redirect/RedirectModeHandler.php#L132

    With:
    $domain = “domain-a.ddev.site“
    $redirectDomain = “domain-aXddev.site”

    Is:
    if (preg_match(‘/(?:^|\\.)’ . $domain . ‘$/’, $redirectDomain)) {

    Should be:
    if (preg_match(‘/(?:^|\\.)’ . preg_quote($domain, ‘/’) . ‘$/’, $redirectDomain)) {

  4. Torben Hansen commented 04/27/23, 14:32

    The whole referer/refererDomains redirect stuff in ext:felogin is IMO way too complicated/error prone and should be simplified. Since the feature is broken since 2019 and nobody ever noticed, I suggest to completely remove it in v12, where we have BeforeRedirectEvent PSR-14 event to modify the final redirect as required.

  5. Gerrit Code Review pushed patch set 1 for main to change 78883 status New Under Review 04/27/23, 15:09

  6. Gerrit Code Review pushed patch set 2 for main to change 78883 04/27/23, 15:13

  7. Gerrit Code Review pushed patch set 3 for main to change 78883 05/03/23, 09:50

  8. Gerrit Code Review pushed patch set 4 for main to change 78883 07/06/23, 08:39

  9. Gerrit Code Review pushed patch set 5 for main to change 78883 07/06/23, 10:19

  10. Gerrit Code Review pushed patch set 1 for 12.4 to change 80071 07/24/23, 13:18

  11. Ayke Halder commented and changed status Under Review Resolved done 0 % 100 % 07/24/23, 13:20

    Applied in changeset commit:67dac52a18e3212291c2871aae6f3993d2348c94.

  12. Gerrit Code Review pushed patch set 1 for 11.5 to change 80132 status Resolved Under Review 07/24/23, 14:47

  13. Ayke Halder commented and changed status Under Review Resolved 07/24/23, 14:50

    Applied in changeset commit:eb73791999228e1744966b07dcac81bcf90a4225.

  14. Benni Mack changed status Resolved Closed 07/09/24, 12:46