Skip to content

Commit 0e0aca5

Browse files
committed
Verify endpoint selection candidates with host attribute are ignored if request doesn't match the configured hosts. (#18820)
1 parent 3e9ff6b commit 0e0aca5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Umbraco.Web.Website/Routing/EagerMatcherPolicy.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc.Controllers;
44
using Microsoft.AspNetCore.Routing;
@@ -126,8 +126,20 @@ public async Task ApplyAsync(HttpContext httpContext, CandidateSet candidates)
126126
return;
127127
}
128128

129+
// If it's an attribute routed IVirtualPageController with a Host attribute we should ignore if the host doesn't match the current request.
130+
// Maybe we would expect that it wouldn't be in the provided CandidateSet, but it will be included just based on the Route.
131+
// See: https://github.com/umbraco/Umbraco-CMS/issues/16816
132+
if (controllerTypeInfo is not null && controllerTypeInfo.IsType<IVirtualPageController>())
133+
{
134+
HostAttribute? hostAttribute = controllerTypeInfo.GetCustomAttribute<HostAttribute>();
135+
if (hostAttribute is not null && hostAttribute.Hosts.InvariantContains(httpContext.Request.Host.Value) is false)
136+
{
137+
continue;
138+
}
139+
}
140+
129141
// If it's an UmbracoPageController we need to do some domain routing.
130-
// We need to do this in oder to handle cultures for our Dictionary.
142+
// We need to do this in order to handle cultures for our Dictionary.
131143
// This is because UmbracoPublishedContentCultureProvider is ued to set the Thread.CurrentThread.CurrentUICulture
132144
// The CultureProvider is run before the actual routing, this means that our UmbracoVirtualPageFilterAttribute is hit AFTER the culture is set.
133145
// Meaning we have to route the domain part already now, this is not pretty, but it beats having to look for content we know doesn't exist.

0 commit comments

Comments
 (0)