Skip to content

Introduce KestrelServerOptions.AllowUnsafeHostHeaderOverride #48461

@amcasey

Description

@amcasey

Background and Motivation

At the request of an internal partner, #39334 introduced an internal API and corresponding appcontext switch that made it possible to overwrite an incorrect Host header with a value derived from an absolute-form request target to handle the surprisingly common client behavior of missing the line-break after the host header, as IIS/Http.Sys did. This PR upgrades it to a public API since those clients aren't going away. The behavior is the same, it just has a name and a doc comment intended for broader consumption.

Issue: #39335
PR: #48460

Proposed API

namespace Microsoft.AspNetCore.Server.Kestrel.Core;

public class KestrelServerOptions
{
+    public bool AllowUnsafeHostHeaderOverride { get; set; }
}

Usage Examples

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseKestrel(serverOptions => {
    serverOptions.AllowUnsafeHostHeaderOverride = true
});

Alternative Designs

We could add a new configuration setting, but we don't really want this to be widely used (since it can hide security threats) and the only existing consumer configured it in code.

Risks

Opting in to this setting makes it easier to write a less secure server.

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions