Skip to content

Request "/foo/" incorrectly matches to Ingress rule with Exact Path "/foo" #2959

@specialforest

Description

@specialforest

Describe the bug

@miaxzhitong found an issue when Ingress rule with Exact Path "/foo" matches a request "/foo/" (and the other way around too). Per https://kubernetes.io/docs/concepts/services-networking/ingress/#examples it should not match:

Kind Path(s) Request path(s) Matches?
Exact /foo /foo/ No
Exact /foo/ /foo No

To Reproduce

Define ingress rule

spec:
  rules:
  - http:
      paths:
      - backend:
          service:
            name: bar
            port:
              number: 443
        path: /foo/
        pathType: Exact

Send a request "/foo".

or with unit test:

   [Fact]
   public async Task ExactPathRouting_Works()
   {
       var routes = new[]
       {
           new RouteConfig()
           {
               RouteId = "route1",
               ClusterId = "cluster1",
               Match = new RouteMatch { Path = "/api" }
           }
       };

       using var host = await CreateHostAsync(routes);
       var client = host.GetTestClient();

       // Positive
       var response = await client.GetAsync("/api");
       response.EnsureSuccessStatusCode();
       Assert.Equal("route1", response.Headers.GetValues("route").SingleOrDefault());

       // Negative
       response = await client.GetAsync("/api/");
       Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
   }

Further technical details

Related to dotnet/aspnetcore#4220

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't workingneeds-author-actionAn issue or pull request that requires more info or actions from the author.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions