Make sure BTCPayServer does not take the culture of the server

This commit is contained in:
nicolas.dorier 2021-05-06 20:28:02 +09:00
parent 86092fc955
commit 4b30132d06
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
3 changed files with 35 additions and 3 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;
using System.Threading.Tasks;
@ -32,6 +33,8 @@ namespace BTCPayServer.Hosting
public async Task Invoke(HttpContext httpContext)
{
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
try
{
var bitpayAuth = GetBitpayAuth(httpContext, out bool isBitpayAuth);

View File

@ -32,6 +32,7 @@ using Microsoft.Net.Http.Headers;
using NBitcoin;
using Microsoft.AspNetCore.Mvc;
using BTCPayServer.Controllers.GreenField;
using System.Globalization;
namespace BTCPayServer.Hosting
{
@ -113,6 +114,7 @@ namespace BTCPayServer.Hosting
o.Filters.Add(new XContentTypeOptionsAttribute("nosniff"));
o.Filters.Add(new XXSSProtectionAttribute());
o.Filters.Add(new ReferrerPolicyAttribute("same-origin"));
o.ModelBinderProviders.Insert(0, new ModelBinders.DefaultModelBinderProvider());
//o.Filters.Add(new ContentSecurityPolicyAttribute()
//{
// FontSrc = "'self' https://fonts.gstatic.com/",
@ -121,7 +123,7 @@ namespace BTCPayServer.Hosting
// StyleSrc = "'self' 'unsafe-inline'",
// ScriptSrc = "'self' 'unsafe-inline'"
//});
})
})
.ConfigureApiBehaviorOptions(options =>
{
options.InvalidModelStateResponseFactory = context =>
@ -142,8 +144,6 @@ namespace BTCPayServer.Hosting
.AddPlugins(services, Configuration, LoggerFactory)
.AddControllersAsServices();
services.TryAddScoped<ContentSecurityPolicies>();
services.Configure<IdentityOptions>(options =>
{

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using BTCPayServer.Payments;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace BTCPayServer.ModelBinders
{
public class DefaultModelBinderProvider : IModelBinderProvider
{
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
if (context.Metadata.ModelType == typeof(decimal) || context.Metadata.ModelType == typeof(decimal?))
return new InvariantDecimalModelBinder();
if (context.Metadata.ModelType == typeof(PaymentMethodId))
return new PaymentMethodIdModelBinder();
if (context.Metadata.ModelType == typeof(WalletIdModelBinder))
return new ModelBinders.WalletIdModelBinder();
if (typeof(DateTimeOffset).GetTypeInfo().IsAssignableFrom(context.Metadata.ModelType) ||
typeof(DateTimeOffset?).GetTypeInfo().IsAssignableFrom(context.Metadata.ModelType))
{
return new DateTimeOffsetModelBinder();
}
return null;
}
}
}