1
0
mirror of https://github.com/bitwarden/server.git synced 2025-03-12 13:29:14 +01:00

adjust fido content type with middleware

This commit is contained in:
Kyle Spearrin 2017-06-22 23:15:28 -04:00
parent ca979e0c40
commit c069fad4e7
3 changed files with 42 additions and 2 deletions

View File

@ -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[]
{

View File

@ -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);
}
}
}

View File

@ -141,6 +141,8 @@ namespace Bit.Api
})
.AddDebug();
app.UseMiddleware<AdjustHeadersMiddleware>();
// Rate limiting
app.UseMiddleware<CustomIpRateLimitMiddleware>();