RequestBodyLimit

Bounds the size of request bodies on the embedded servers.

Without a bound, a caller (authenticated or not) can have the server buffer an arbitrarily large body while ContentNegotiation parses it. The limit is enforced twice, because both signals are attacker-controlled: the declared Content-Length is checked first as a cheap reject, and the body is then read through a bounded buffer, which is what actually enforces it for chunked requests that declare no length. Either failure answers 413 Payload Too Large.

Install it after the authentication gate (so unauthenticated callers are refused before any body is read) and before the routes. The body is read before the handler runs, so a handler's own error handling can never turn an oversized request into a different status.

Properties

Link copied to clipboard

1 MiB: far above any JSON request these servers take, far below what exhausts memory.

Functions

Link copied to clipboard
fun install(application: Application, maxBytes: Long = DEFAULT_MAX_BYTES)