spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

DataBufferLimitException in WebFlux controllers should result in 413 instead of 500

Open singhbaljit opened this issue 1 year ago • 1 comments

When using Spring WebFlux, there is a maximum limit on the payload size, defined by spring.codec.max-in-memory-size (default value is 256KB). If a request is made with a body exceeding this size, DataBufferLimitException is thrown. The default error handler then returns a 500 Internal Server Error response. This is actually not a server side error, but instead a server side validation. This should result in 413 Content Too Large instead.

Spring Boot version: 3.2.1

singhbaljit avatar Jan 25 '24 02:01 singhbaljit

Few more thoughts: the error handler probably shouldn't map DataBufferLimitException to 413 directly, as there can be other reasons for the exception. For example, WebClient can also throw this exception, which likely is a server side error. I suppose we should map (i.e. onErrorMap) to another exception that always result in a 413; this should only happen when parsing the body of request. But I'm not very familiar with the spring-framework code, so just guessing.

Also, I do not know if this happens in WebMVC all well; that is a 500 instead of a 413, but it should be straightforward to validate.

singhbaljit avatar Jan 25 '24 15:01 singhbaljit

Closing in favor of PR #32558

snicoll avatar Apr 04 '24 14:04 snicoll