Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
#66912 reports the same root cause for [FromBody(EmptyBodyBehavior = Allow)]. #67591 fixed it for 11.0; this asks for that fix in 10.0 servicing.
With EnableRequestDelegateGenerator (on by default under PublishAot and PublishTrimmed), the generator in 10.0 gives one interceptor to minimal API handlers with the same HTTP method and return type whose parameters have the same types and names, even when their binding attributes differ. The second endpoint then binds its parameters as the first one does:
MapGet("/query", (Guid id) => ...)andMapGet("/header", ([FromHeader(Name = "X-Id")] Guid id) => ...):/headerreadsidfrom the route or the query string. A request carrying theX-Idheader gets 400, and/header?id=...without the header gets 200.([FromHeader(Name = "X-A")] string value)and([FromHeader(Name = "X-B")] string value):/header-breads theX-Aheader.
The build reports no warning or diagnostic, and startup no error. With the generator off, every endpoint binds as written.
On release/10.0 (55d77e1), endpoints are grouped with Endpoint.SignatureEquals (Endpoint.cs#L116-L134), which compares parameters with EndpointParameter.SignatureEquals: type, symbol name and keyed-service key only (EndpointParameter.cs#L604-L611). #67591 replaced it on main with EndpointParameter.Equals, which also compares the binding source, the lookup name, the ordinal and optionality, and added MapAction_ExplicitHeaderParam_SharedDelegateSignature_PreservesBindingName, which covers the header-name case above. On 11.0.0-rc.1 every endpoint of the repro binds correctly.
For the servicing decision:
- Impact: in an app that enables the generator (every app published with
PublishAotorPublishTrimmed) and has two such handlers, the second binds from another source or under another name, with no diagnostic. 10.0 is an LTS release. - Regression: no.
release/8.0andrelease/9.0have the same comparison. - Risk: low. The change (8 lines added and 11 removed in two files, whose context matches
release/10.0) and its regression tests have been onmainsince 11.0-preview7 and ship in 11.0 RC1. - Workaround: give the parameters of such handlers different names.
Expected Behavior
Each endpoint binds its parameters as its own attributes say, with the generator on or off, as on 11.0.0-rc.1.
Steps To Reproduce
Repro project: https://github.com/AdCodicem/dotnet-upstream-repros/tree/main/aspnetcore-rdg-shared-interceptor. ./repro.sh builds and runs it with the generator off, then on; REPRO_TFM=net11.0 ./repro.sh does the same on .NET 11.
Repro.csproj (the repository's version takes the target framework from REPRO_TFM; net10.0 is its default):
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
</Project>Program.cs:
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateSlimBuilder(args);
builder.Logging.ClearProviders();
builder.WebHost.UseUrls("http://127.0.0.1:0");
var app = builder.Build();
// Same parameter type and name; only the binding attributes differ.
app.MapGet("/query", (Guid id) => $"query {id}");
app.MapGet("/header", ([FromHeader(Name = "X-Id")] Guid id) => $"header {id}");
// Same source, different header names.
app.MapGet("/header-a", ([FromHeader(Name = "X-A")] string value) => $"X-A {value}");
app.MapGet("/header-b", ([FromHeader(Name = "X-B")] string value) => $"X-B {value}");
await app.StartAsync();
using var client = new HttpClient { BaseAddress = new Uri(app.Urls.First()) };
var id = Guid.NewGuid();
await Send("/query?id=" + id, null);
await Send("/header", ("X-Id", id.ToString()));
await Send("/header-a", ("X-A", "a"));
await Send("/header-b", ("X-B", "b"));
// What the second endpoint of each pair actually binds.
await Send("/header?id=" + id, null);
await Send("/header-b", ("X-A", "a"));
await app.StopAsync();
async Task Send(string path, (string Name, string Value)? header)
{
using var request = new HttpRequestMessage(HttpMethod.Get, path);
if (header is { } h) request.Headers.Add(h.Name, h.Value);
using var response = await client.SendAsync(request);
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine($"GET {path,-48} {(header is { } x ? x.Name + ": " + x.Value : ""),-44} -> {(int)response.StatusCode} {body}");
}Output on SDK 10.0.401:
== EnableRequestDelegateGenerator=false
GET /query?id=5f4bfee9-a79e-4040-9c7c-12eef7409de0 -> 200 query 5f4bfee9-a79e-4040-9c7c-12eef7409de0
GET /header X-Id: 5f4bfee9-a79e-4040-9c7c-12eef7409de0 -> 200 header 5f4bfee9-a79e-4040-9c7c-12eef7409de0
GET /header-a X-A: a -> 200 X-A a
GET /header-b X-B: b -> 200 X-B b
GET /header?id=5f4bfee9-a79e-4040-9c7c-12eef7409de0 -> 400
GET /header-b X-A: a -> 400
== EnableRequestDelegateGenerator=true
GET /query?id=83c65e51-e418-4371-a2fb-6dc95b51a845 -> 200 query 83c65e51-e418-4371-a2fb-6dc95b51a845
GET /header X-Id: 83c65e51-e418-4371-a2fb-6dc95b51a845 -> 400
GET /header-a X-A: a -> 200 X-A a
GET /header-b X-B: b -> 400
GET /header?id=83c65e51-e418-4371-a2fb-6dc95b51a845 -> 200 header 83c65e51-e418-4371-a2fb-6dc95b51a845
GET /header-b X-A: a -> 200 X-B a
On SDK 11.0.100-rc.1.26425.128 (net11.0), the generator-on run prints the same results as the control.
Exceptions (if any)
None; the wrong binding is silent.
.NET Version
10.0.401
Anything else?
- ASP.NET Core: 10.0.12 (the generator ships in
Microsoft.AspNetCore.App.Ref) - No IDE (CLI); Windows 11 (10.0.26200) x64 and Ubuntu x64
- Handlers that differ only by a parameter's default value still share an interceptor on 11.0 as well: Request Delegate Generator: handlers that differ only by a parameter's default value share one interceptor, InvalidCastException at startup #69675.
Found while adding native AOT checks to AdCodicem.ValueObjects. Investigation and write-up assisted by Claude (Anthropic); the linked repro was run on Windows 11 and Ubuntu, and I reviewed this report.
Activity
earbona23 commentedon Nov 1, 2026
I ran into this from a different direction and I think the impact is wider than the issue currently records, so I am adding what I measured in case it helps the triage.
The collapse is not limited to picking the wrong parameter source. When the endpoint that loses the collision is a form endpoint, it also loses the antiforgery metadata, because
AntiforgeryMetadata.ValidationRequiredis emitted from inside the per-interceptor emission inStaticRouteHandlerModel.Emitter.cs. The endpoint stops being treated as a form endpoint at all, so it is never marked as requiring a token.Minimal repro,
AddAntiforgery()andUseAntiforgery()wired up, nothing else unusual:Reading
Endpoint.Metadata.GetMetadata<IAntiforgeryMetadata>()for/b-formfrom inside the running app:POST /b-form?v=x, no tokenRequiresValidation = true<PublishAot>true</PublishAot>Same result on 8.0.33, 9.0.22 and 10.0.14.
<PublishAot>true</PublishAot>on its own is enough, which is whatdotnet new webapiaotputs in the project file, so no extra opt-in is involved. The generated code for the collided endpoint shows the inherited source directly:while an uncollided
[FromForm]endpoint in the same file getsSource = FormBodyand theAntiforgeryMetadata.ValidationRequiredline.Scope of the collision, measured rather than assumed:
Map*verb helper is part of the key.MapGet("/plain", (string v))beforeMapPost("/form", ([FromForm] string v))does not collide.([FromForm] int n)does not collide with(string v), and changing the return type separates them..csfile, which is the case that worries me most, since the endpoint that breaks is not the one being edited.POST /plain?v=hellogoes from 200 to a failure.DisableAntiforgery()does not leak between the two.One thing that limits this, which I want to state plainly: the collided endpoint is also broken for legitimate use. A real form post with a valid token to
/b-formreturns 400 in the same build, because the handler is no longer reading the form. So a developer who exercises their own form will notice something is wrong. The exposure is the leftover query-string path into a handler that was written to be CSRF protected, which matters most when the collision is introduced later by an unrelated endpoint added elsewhere in the solution.A separate thing I noticed while measuring this, which may deserve its own issue: in generator builds the correct rejection of a token-less form post is an unhandled exception rather than a 400. The generated
TryResolveFormAsynctouches the form without consultingIAntiforgeryValidationFeature, soFormFeature.HandleUncheckedAntiforgeryValidationFeaturethrows:and the response is 500 where the runtime path logs
RequestDelegateFactory[9]and returns 400. It is fail closed, the handler does not run, so it is a robustness and diagnosability problem rather than a security one. I mention it because it also makes this family of bugs easy to misread when testing: a check that only looks for "not 400" will score the safe cases as broken too.This is the same root cause you already describe, so I am not opening anything new. I am adding it here because this issue is the one asking for the 10.0 backport, and the antiforgery consequence seems like it belongs in that servicing argument: on 8.0, 9.0 and 10.0 the collapse can take an endpoint the developer wrote as a CSRF-protected form endpoint and leave it reachable without a token. Happy to put the repro in a gist or send a PR to the test suite if that would help.