From 33d3a25928fb16810c7e48a8ee6c5817495ccff6 Mon Sep 17 00:00:00 2001 From: d11n Date: Wed, 21 Feb 2024 13:34:12 +0100 Subject: [PATCH] Apps: Don't redirect .onion requests to canonical domain (#5776) Fixes #5729. --- BTCPayServer/Filters/DomainMappingConstraintAttribute.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BTCPayServer/Filters/DomainMappingConstraintAttribute.cs b/BTCPayServer/Filters/DomainMappingConstraintAttribute.cs index 5b3f5153d..ecb6a66a6 100644 --- a/BTCPayServer/Filters/DomainMappingConstraintAttribute.cs +++ b/BTCPayServer/Filters/DomainMappingConstraintAttribute.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using System.Linq; +using BTCPayServer.Abstractions.Extensions; using BTCPayServer.Services; using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.Extensions.DependencyInjection; @@ -25,7 +25,7 @@ namespace BTCPayServer.Filters { var req = context.RouteContext.HttpContext.Request; var policies = context.RouteContext.HttpContext.RequestServices.GetService(); - var mapping = policies?.DomainToAppMapping?.ToList() ?? new List(); + var mapping = policies?.DomainToAppMapping?.ToList() ?? []; if (policies is { RootAppId: { } rootAppId, RootAppType: { } rootAppType }) { mapping.Add(new PoliciesSettings.DomainToAppMappingItem @@ -37,7 +37,7 @@ namespace BTCPayServer.Filters } // If we have an appId, we can redirect to the canonical domain - if ((string)context.RouteContext.RouteData.Values["appId"] is string appId) + if ((string)context.RouteContext.RouteData.Values["appId"] is { } appId && !req.IsOnion()) { var redirectDomain = mapping.FirstOrDefault(item => item.AppId == appId)?.Domain; // App is accessed via path, redirect to canonical domain