Skip to content

Forwarded Headers Middleware: X-Forwarded-Prefix Applied when it comes from an Unknown Proxy #61449

Open
@yannic-hamann-abb

Description

@yannic-hamann-abb

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am not understanding the security concerns why X-Forwarded-Fields should be only allowed for known proxies - but that is what the documentation implies.
The current implementation of ForwardedHeadersMiddleware only breaks and logs Unknown proxy: {RemoteIpAndPort} when the flag ForwardedHeaders.XForwardedFor is set.

Documentation says:

Address ranges of known networks to accept forwarded headers from.

With other words you can end up with a configuration like:

var options = new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedPrefix };

which modifies your request.PathBase even though it comes from an unknown proxy. Is this a bug or by design? If by design maybe documentation could be improved.
XForwardedProto and XForwardedHost are potentially bypassed in the same way.

Expected Behavior

Unknown due to my limited security understanding. Maybe HttpContext.Request.PathBase should be left untouched by the middleware when header comes from an unknown proxy.

Steps To Reproduce

var options = new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedPrefix };
// options.KnownNetworks.Add(new Microsoft.AspNetCore.HttpOverrides.IPNetwork(IPAddress.Parse("0.0.0.0"), 0));
_application.UseForwardedHeaders(options);

Exceptions (if any)

No response

.NET Version

9.0.104

Anything else?

I would like to contribute to fix this issue. I am planning to write some tests tomorrow for this and suggest a PR with some more detailed description of the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewares

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions