From 3c344331afc0926875021e78c4ae36b19687f43e Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Fri, 10 Feb 2023 18:15:54 +0100 Subject: [PATCH] Improve domain mapping constraint - Fix potential double assignment to appId, leading to an [exception](https://pastebin.com/j8dhtcTE) - Add port to redirect, which makes it work in dev env --- .../Filters/DomainMappingConstraintAttribute.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/BTCPayServer/Filters/DomainMappingConstraintAttribute.cs b/BTCPayServer/Filters/DomainMappingConstraintAttribute.cs index b8145d08b2..ff59fc96f7 100644 --- a/BTCPayServer/Filters/DomainMappingConstraintAttribute.cs +++ b/BTCPayServer/Filters/DomainMappingConstraintAttribute.cs @@ -38,8 +38,9 @@ public bool Accept(ActionConstraintContext context) if (matchedDomainMapping != null) { var req = context.RouteContext.HttpContext.Request; - var url = new UriBuilder(req.Scheme, matchedDomainMapping.Domain).ToString(); - context.RouteContext.HttpContext.Response.Redirect(url); + var uri = new UriBuilder(req.Scheme, matchedDomainMapping.Domain); + if (req.Host.Port.HasValue) uri.Port = req.Host.Port.Value; + context.RouteContext.HttpContext.Response.Redirect(uri.ToString()); return true; } } @@ -55,15 +56,17 @@ public bool Accept(ActionConstraintContext context) return false; if (appType != matchedDomainMapping.AppType) return false; - context.RouteContext.RouteData.Values.Add("appId", matchedDomainMapping.AppId); - return true; + if (!hasAppId) + { + context.RouteContext.RouteData.Values.Add("appId", matchedDomainMapping.AppId); + return true; + } } } - if (AppType == policies.RootAppType) + if (AppType == policies.RootAppType && !hasAppId && !string.IsNullOrEmpty(policies.RootAppId)) { context.RouteContext.RouteData.Values.Add("appId", policies.RootAppId); - return true; }