Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature main 10818 fix redirect loop #10822

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jonasraoni
Copy link
Contributor

No description provided.

$multiLingual = count($this->_getContextAndLocales($request, $contextPath)[1]) > 1;

if (!$multiLingual && !$urlLocale && !$setLocale || $multiLingual && !$setLocale && $urlLocale === Locale::getLocale()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the common parts, but the initial intention was just to drop the requirement of knowing the operator precedence.

return;
}

$sessionLocale = (function (string $l) use ($request): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see a reason to create a closure here, so I extracted the code out of it and tried to simplify.

$indexUrl = $this->getIndexUrl($request);
$uri = preg_replace("#^{$indexUrl}#", '', $setLocale ? ($_SERVER['HTTP_REFERER'] ?? '') : $request->getCompleteUrl(), 1);
Copy link
Contributor Author

@jonasraoni jonasraoni Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the line 525 there's a str_replace('@', '', $url). Was it used to do some kind of abuse (redirect user to another system and pass credentials)?

If yes, then I think the HTTP_REFERER should receive the same treatment, as it's also unsafe. Depending on what was the original issue, perhaps we should check if the destiny URL belongs to us (e.g. same domain/base path).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added here: #10478.
So maybe @asmecher would know best.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my brain is not functioning well enough to see/think what could happen with HTTP_REFERER 😅
It could be a fully different web page from where the request with setLocale is coming and we would then try to replace contexPath+oldLocale with contextPath+newLocale in that URL, add that string then to $indexUrl (which is checking after our base URL) and redirect to it 🤔
And I just cannot figure out what 'bad' could happen thereby... so that we take good care of it... 🤔

$indexUrl = $this->getIndexUrl($request);
$uri = preg_replace("#^{$indexUrl}#", '', $setLocale ? ($_SERVER['HTTP_REFERER'] ?? '') : $request->getCompleteUrl(), 1);
$newUrlLocale = $multiLingual ? "/{$sessionLocale}" : '';
$pathInfo = ($uri)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was here, when the $uri is /, then the code attempts to do the replace, nothing is replaced and we get into a loop.

@jonasraoni
Copy link
Contributor Author

Hi @jyhein! I think you were the last person to work on this part of the code, if you can do a review, great :)

@jonasraoni jonasraoni requested a review from asmecher January 18, 2025 15:50
@jonasraoni jonasraoni linked an issue Jan 18, 2025 that may be closed by this pull request
@bozana
Copy link
Collaborator

bozana commented Jan 31, 2025

Hi @jonasraoni, I reviewed your changes and I think everything is fine.
Except that I am not sure what we need to do with that HTTP_REFERER...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redirect loop when accessing "index.php/"
2 participants