Skip to content
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.AspNetCore.Http;

namespace Microsoft.AspNetCore.Builder;

Expand All @@ -22,6 +23,17 @@ public static class RoutingEndpointConventionBuilderExtensions
/// An empty collection means any host will be accepted.
/// </param>
/// <returns>A reference to this instance after the operation has completed.</returns>
/// <remarks>
/// APIs that rely on the <see href="https://developer.mozilla.org/docs/Web/HTTP/Headers/Host">Host header</see>, such as
/// <see cref="HttpRequest.Host"/> and <see cref="RequireHost"/>, are vulnerable to potential spoofing by clients.
///
/// To prevent host and port spoofing, use one of the following approaches:
///
/// <list type="bullet">
/// <item>Use <see cref="HttpContext.Connection"/> (<see cref="ConnectionInfo.LocalPort"/>) where the ports are checked.</item>
/// <item>Employ <see href="https://learn.microsoft.com/aspnet/core/fundamentals/servers/kestrel/host-filtering">Host filtering</see>.</item>
/// </list>
Comment thread
bseptember marked this conversation as resolved.
Outdated
/// </remarks>
public static TBuilder RequireHost<TBuilder>(this TBuilder builder, params string[] hosts) where TBuilder : IEndpointConventionBuilder
{
ArgumentNullException.ThrowIfNull(builder);
Expand Down