Skip to content

Commit

Permalink
Improve domain mapping constraint
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dennisreimann committed Feb 10, 2023
1 parent d14ce2a commit 3c34433
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions BTCPayServer/Filters/DomainMappingConstraintAttribute.cs
Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 3c34433

Please sign in to comment.