Skip to content

Conversation

@robinroloff
Copy link

This PR fixes the "sameSourceAndTarget" and check. Previously, it was not correctly comparing the source and target host.

On the frontend, it was comparing the sourceHost to the host the user is currently on:

if (!host || host === location.host) {

This also had the unwanted side effect that this check would only work when the user is creating a redirect for the very same domain they are currently on (most of the time the primary site). When they were creating a redirect for another site, this would only be checked on the backend and give the user a generic error "Redirect could not be created".

And on the backend, it was creating the redirect using the $host variable:

$redirect = $this->redirectStorage->getOneBySourceUriPathAndHost($sourceUriPath, $host ?: null, false);

and then comparing it against itself:

$isSame = $this->isSame($sourceUriPath, $targetUriPath, $host, $statusCode, $redirect);

Example:

Domain: www.foo.bar
Source Path: test
Target Path: www.example.com/test

Before: This throws an error
Now: Works as expected

Copy link
Member

@Sebobo Sebobo left a comment

Choose a reason for hiding this comment

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

Thx for working on this!

Though this change doesn't look right yet to me. But I agree that it wasn't correct before.

return $redirect->getSourceUriPath() === $sourceUriPath
&& $redirect->getTargetUriPath() === $targetUriPath
&& $redirect->getHost() === $host
&& $redirect->getHost() === $targetHost
Copy link
Member

Choose a reason for hiding this comment

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

The host is used to determine whether a redirect is triggered in the middleware. So it has no relation to the target. IMO this part of the change is incorrect.
I think rather the targetUriPath should be checked twice in case one time it was given without host and one time with a host.

const parsedSourceUrl: URL = UrlUtil.parseURL(sourceUriPath, location.origin);
const parsedTargetUrl: URL = UrlUtil.parseURL(targetUriPath, location.origin);

if ((!host || host === parsedTargetUrl.host) && parsedSourceUrl.pathname === parsedTargetUrl.pathname) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be instead:

if (parsedSourceUrl.hostname === parsedTargetUrl.hostname && parsedSourceUrl.pathname === parsedTargetUrl.pathname) {

@Sebobo Sebobo requested a review from dlubitz February 9, 2026 09:16
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.

2 participants