Skip to content

[release/10.0] Refactor param binding failure handling in RequestDelegate#66221

Open
github-actions[bot] wants to merge 4 commits intorelease/10.0from
backport/pr-64539-to-release/10.0
Open

[release/10.0] Refactor param binding failure handling in RequestDelegate#66221
github-actions[bot] wants to merge 4 commits intorelease/10.0from
backport/pr-64539-to-release/10.0

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 8, 2026

Backport of #64539 to release/10.0

/cc @BrennanConroy @marcominerva

Refactor param binding failure handling in RequestDelegate

Description

Validation support was added in 10.0.

It works by adding an endpoint filter that checks if an endpoint should have validation applied to it, if it does then it wraps the endpoint delegate in a new delegate that will run validation, otherwise it just returns the original endpoint delegate without wrapping it.

The bug, which looks like it's existed for years, is that if an endpoint filter returns the original endpoint delegate we would think that a filter had been wrapped around the original delegate and still call it for failed parameter binding, even though the delegate was never wrapped. This resulted in the endpoint being called when it normally shouldn't be.

e.g.

app.MapGet("/x/{id}", (Guid id) => id.ToString());

In the above snippet, if validation is added via AddValidation on the service collection, then a request to /x/invalid-guid would still call the id.ToString() code even though we've set a 400 status code and shouldn't be calling the delegate.

Fixes #64341

Not planning on backporting to 9.0 and 8.0 since we haven't seen complaints for those versions and validation is new in 10.0 which is the main motivator for backporting this.

Customer Impact

Highly requested bug fix, and blocking some customers from using the new validation feature.

Regression?

  • Yes
  • No

Validation is new in 10.0, and the bug has been there since before 10.0.

Risk

  • High
  • Medium
  • Low

Improved test coverage, simple fix.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

Refactor `RequestDelegateFactory` to handle parameter binding
failures more flexibly:
- Execute filter pipelines on failure if filters are present
  and return type is `ValueTask<object?>`, allowing filters
  to observe/modify the 400 response.
- Short-circuit with a 400 response if no filters are present.
- Simplify logic using `Expression.Condition` and
  `Expression.Block`.

Add new test cases in `RouteHandlerEndpointRouteBuilderExtensionsTest.cs`:
- Validate behavior with/without filters and custom responses.
- Ensure handlers are not executed on binding failure.
… between RDG/RDF

This confirm that the behavior is the same across runtime and compile-time generated handler implementations.
Added explanatory comments to RequestDelegateFactory describing the checkWasParamCheckFailure conditional expression. These comments clarify how parameter binding or validation failures result in a 400 response, while successful checks invoke the handler method. No functional changes were made.
@github-actions github-actions bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Apr 8, 2026
@BrennanConroy
Copy link
Copy Markdown
Member

cc @artl93 for servicing consideration.

Copy link
Copy Markdown
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newer feature in 10.0 exposed this issue more prominently. Current behavior is unexpected. Customer reported. Approved.

@BrennanConroy BrennanConroy added the Servicing-consider Shiproom approval is required for the issue label Apr 9, 2026
@BrennanConroy BrennanConroy added this to the 10.0.x milestone Apr 9, 2026
@BrennanConroy BrennanConroy added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Apr 9, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Hi @github-actions[bot]. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed.

@BrennanConroy
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants