microsoft / reverse-proxy

A toolkit for developing high-performance HTTP reverse proxy applications.

Home Page:https://microsoft.github.io/reverse-proxy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MaxRequestBodySize on RouteConfig class has no effect

nazirj-absa opened this issue · comments

commented

Describe the bug

The value is set in code. The RateLimiterPolicy works brilliantly.
However, we would like to limit the body request on certain endpoints.
MaxRequestBodySize - is different per route.
However, it has no effect.
Setting the value to a modest 53 bytes on a limit of 50 bytes has no effect.

RouteConfig routeItem = new RouteConfig() { RouteId = $"route-{endpoint.Name}-{Random.Shared.Next()}", ClusterId = endpoint.ClusterId, Match = new RouteMatch { Path = $"/{pathPrefix}{endpoint.MatchPath}" }, RateLimiterPolicy = endpoint.RateLimiterPolicy, MaxRequestBodySize = endpoint.MaxRequestBodySize, Transforms = new List<Dictionary<string, string>>() { new Dictionary<string, string> { { "PathSet", endpoint.TransformPath } } }, AuthorizationPolicy = endpoint.AuthorizationPolicy };

To Reproduce

Use postman to perform a post or put with the json payload of:
{"val":"test","val1":"test","val2":"test11111111111111111111111111111111111111111111111111111111111"}
i.e. 101 bytes.

If the route has MaxRequestBodySize of 50 bytes - the request still returns with a 200 status.

        [HttpPut("UpdateItem")]
        public ActionResult UpdateItem([FromBody] JsonElement body)
        {
            return Ok($"updated - {body.ToString()}");
        }

        [HttpPost("CreateItem")]
        public ActionResult CreateItem([FromBody] JsonElement body)
        {
            return Ok($"created - {body.ToString()}");
        }

Further technical details

  • Include the version of the packages you are using
  • The platform is Windows.
  • Yarp version 2.1.0