#100215Redirect by redirectMode "refererDomains" is broken
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
Related issues 1
History 714
-
Torben Hansen changed description 03/18/23, 18:25
-
Torben Hansen changed Related to #98372 03/20/23, 17:32
-
Ayke Halder commented 04/27/23, 14:21
-
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
BeforeRedirectEventPSR-14 event to modify the final redirect as required. -
Gerrit Code Review pushed patch set 1 for main to change 78883 status
NewUnder Review 04/27/23, 15:09 -
Gerrit Code Review pushed patch set 2 for main to change 78883 04/27/23, 15:13
-
Gerrit Code Review pushed patch set 3 for main to change 78883 05/03/23, 09:50
-
Gerrit Code Review pushed patch set 4 for main to change 78883 07/06/23, 08:39
-
Gerrit Code Review pushed patch set 5 for main to change 78883 07/06/23, 10:19
-
Gerrit Code Review pushed patch set 1 for 12.4 to change 80071 07/24/23, 13:18
-
Ayke Halder commented and changed status
Under ReviewResolved done0 %100 % 07/24/23, 13:20Applied in changeset commit:67dac52a18e3212291c2871aae6f3993d2348c94.
-
Gerrit Code Review pushed patch set 1 for 11.5 to change 80132 status
ResolvedUnder Review 07/24/23, 14:47 -
Ayke Halder commented and changed status
Under ReviewResolved 07/24/23, 14:50Applied in changeset commit:eb73791999228e1744966b07dcac81bcf90a4225.
-
Benni Mack changed status
ResolvedClosed 07/09/24, 12:46
I can confirm this.
Environment:
All cases are only redirecting in the process of a successfull login. So no open redirect here.
To reproduce:
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)) {