dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.55k stars 10.05k forks source link

Route constraints invoked for paths which do not use the route constraint #57572

Closed onionhammer closed 2 months ago

onionhammer commented 2 months ago

Is there an existing issue for this?

Describe the bug

Using a {parameter} in one route and a {*catchall} in another route causes a RouteHandlers to be invoked unrelated requests

Example:

/tiles/{**path} 
/{partner:my_route_constraint}/{form}.js

the my_route_constraint will be invoked with "tiles" as the routeKey value of partner even though the path is not using that constraint, and is more specific (starts with /tiles/) for certain requests

example:

GET /tiles/one_segment <-- this hits the route constraint
GET /tiles/one_segment/two_second <-- this does not hit the route constraint

Expected Behavior

If you specify a prefixed route, it should not hit a route constraint?

Steps To Reproduce

Here is a repo that reproduces the issue:

https://github.com/onionhammer/repro-routing-issue/blob/master/Program.cs

Reference test.http for example requests

Exceptions (if any)

No response

.NET Version

8.0.401

Anything else?

No response

javiercn commented 2 months ago

@onionhammer thanks for contacting us.

This is by design. Routing evaluates the current path against all potential matches as a first step and then applies matcher policies and ordering to get a final result. /tiles/{**path} might not match because it has an HTTP POST constraint and, in that case, /tiles/sample.js will still match and can't be discarded.

onionhammer commented 2 months ago

Why was the choice made to not just route to a more specific path?

dotnet-policy-service[bot] commented 2 months ago

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.