Apps: Don't redirect .onion requests to canonical domain (#5776)

Fixes #5729.
This commit is contained in:
d11n 2024-02-21 13:34:12 +01:00 committed by GitHub
parent c2acff81c6
commit 33d3a25928
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<PoliciesSettings>();
var mapping = policies?.DomainToAppMapping?.ToList() ?? new List<PoliciesSettings.DomainToAppMappingItem>();
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