-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Background and Motivation
By default request/response headers which are not added to the collections of the RequestHeaders and ResponseHeaders properties of the HttpLoggingOptions configuration object are logged with a redacted value.
It would be good to add an option, in scenarios controlled by the developer, to enable the logging of any request or response header.
Examples of scenarios:
- Debugging
- Sensitive data by design of the application never ends up in the headers
- Not predictable headers that must be logged
Proposed API
It can be achieved by allowing new values for the HttpLoggingFields enum. For example:
namespace Microsoft.AspNetCore.HttpLogging;
[Flags]
public enum HttpLoggingFields : long
{
//Existent enum values
None = 0x0,
RequestPath = 0x1,
....
+ RequestHeadersIncludeSensitive = 0x1000,
+ ResponseHeadersIncludeSensitive = 0x2000,
+ RequestPropertiesAndHeadersIncludeSensitive = RequestProperties | RequestHeadersIncludeSensitive,
+ ResponsePropertiesAndHeadersIncludeSensitive = ResponseStatusCode | ResponseHeadersIncludeSensitive,
+ RequestIncludeSensitive = RequestPropertiesAndHeadersIncludeSensitive | RequestBody,
+ ResponseIncludeSensitive = ResponseStatusCode | ResponseHeadersIncludeSensitive | ResponseBody,
+ AllIncludeSensitive = RequestIncludeSensitive | ResponseIncludeSensitive
....
All = Request | Response
}Usage Examples
The developer can opt-in for the new beahvior:
using Microsoft.AspNetCore.HttpLogging;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpLogging(logging =>
{
logging.LoggingFields = HttpLoggingFields.AllIncludeSensitive; //Usage of one of the new enum values
});
var app = builder.Build();
app.UseHttpLogging();
app.Run();This configuration will log all the request/response headers without the redacted value.
Risks
It doesn't affect nor change the current API behavior since the developer must explicitly configure the logging with one of the new values in order to enable the logging for all the headers.
Implementation
The following commit shows how could look like the implementation: liguori@9f35fa9