-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
affected-mostThis issue impacts most of the customersThis issue impacts most of the customersarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing oneseverity-minorThis label is used by an internal toolThis label is used by an internal tool
Milestone
Description
There's lots of advice on how to log the headers and body of an incoming and outgoing http request (and response) on the interwebs:
- https://stackoverflow.com/questions/46361958/asp-net-core-mvc-log-request-body
- https://elanderson.net/2017/02/log-requests-and-responses-in-asp-net-core/
To name a few of them. They are not done in very safe ways:
- Some buffer the entire request body of every request (not respecting the IHttpBufferingFeature). This results in memory bloats (a potential DoS)
- Some don't rewind the Stream properly.
- The implementations aren't lazy
- There are security implications as well (sensitive data may be in headers, other PII, GDPR?)
It seems like lots of people are doing this and doing it incorrectly and inefficiently, we should add a middleware here as this is very common and requires no new dependencies.
Strawman:
public class RequestLoggingMiddlewareExtensions
{
public IApplicationBuilder UseRequestLogging(this IApplicationBuilder app) { }
public IApplicationBuilder UseRequestLogging(this IApplicationBuilder app, RequestLoggingOptions options) { }
}
public class RequestLoggingOptions
{
// Determines if the cookie header is logged
public bool LogCookieHeader { get; set; }
// Determines if the authorization header is logged
public bool LogAuthorizationHeader { get; set; }
// Determines the verbosity of the logs
public RequestLoggingLevel RequestLogLevel { get; set; }
}
[Flags]
public enum RequestLoggingLevel
{
None = 0,
RequestHeaders = 1,
ResponseHeaders = 2,
RequestBody = 4,
ResponseBody = 8,
AllRequest = RequestHeaders | RequestBody
AllResponse = RequestHeaders | RequestBody
All = AllRequest | AllResponse
}
cc @Tratcher
poke, masterjs, SIkebe, BrendanRidenour, markusschaber and 22 more
Metadata
Metadata
Assignees
Labels
affected-mostThis issue impacts most of the customersThis issue impacts most of the customersarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing oneseverity-minorThis label is used by an internal toolThis label is used by an internal tool