diff --git a/src/Api/Controllers/TwoFactorController.cs b/src/Api/Controllers/TwoFactorController.cs index 2a64d69ae0..3e7ee360d3 100644 --- a/src/Api/Controllers/TwoFactorController.cs +++ b/src/Api/Controllers/TwoFactorController.cs @@ -136,7 +136,7 @@ namespace Bit.Api.Controllers } [HttpGet("~/app-id.json")] - //[Produces("application/fido.trusted-apps+json")] + [Produces("application/fido.trusted-apps+json")] [AllowAnonymous] public string GetU2fAppId() { @@ -149,7 +149,7 @@ namespace Bit.Api.Controllers version = new { major = 1, - minor = 1 + minor = 0 }, ids = new string[] { diff --git a/src/Api/Middleware/AdjustHeadersMiddleware.cs b/src/Api/Middleware/AdjustHeadersMiddleware.cs new file mode 100644 index 0000000000..a583c758be --- /dev/null +++ b/src/Api/Middleware/AdjustHeadersMiddleware.cs @@ -0,0 +1,38 @@ +using Bit.Core; +using Microsoft.AspNetCore.Http; +using System.Linq; +using System.Threading.Tasks; + +namespace Bit.Api.Middleware +{ + public class AdjustHeadersMiddleware + { + private readonly RequestDelegate _next; + + public AdjustHeadersMiddleware(RequestDelegate next) + { + _next = next; + } + + public async Task Invoke(HttpContext httpContext, CurrentContext currentContext) + { + httpContext.Response.OnStarting((state) => + { + if(httpContext.Response.Headers.Count > 0 && httpContext.Response.Headers.ContainsKey("Content-Type")) + { + var contentType = httpContext.Response.Headers["Content-Type"].ToString(); + if(contentType.StartsWith("application/fido.trusted-apps+json")) + { + httpContext.Response.Headers.Remove("Content-Type"); + httpContext.Response.Headers.Append("Content-Type", "application/fido.trusted-apps+json"); + } + } + + return Task.FromResult(0); + }, null); + + + await _next.Invoke(httpContext); + } + } +} diff --git a/src/Api/Startup.cs b/src/Api/Startup.cs index 45771229ab..f8faa0ceee 100644 --- a/src/Api/Startup.cs +++ b/src/Api/Startup.cs @@ -141,6 +141,8 @@ namespace Bit.Api }) .AddDebug(); + app.UseMiddleware(); + // Rate limiting app.UseMiddleware();