Repository navigation
Description
Summary
LogbookFilter (and the other server integrations) buffer the entire request body in heap before the application sees the request, with no size limit. An unauthenticated client can crash a JVM with a single chunked POST, even against a route that does not exist or never reads the body. Response bodies are buffered the same way.
This looks like CWE-400 / CWE-770 (allocation of resources without limits). The README already acknowledges the behavior under logbook.write.max-body-size ("Logbook will still buffer the full body"), but there is currently no way to bound the buffer at all.
Affected code
logbook-servlet–RemoteRequest.doBuffer()callsByteStreams.toByteArray(request.getInputStream())with no limit. Buffering is eager (withBody()), so it happens before request filters/body replacers run: anapplication/octet-streamupload is fully read into memory and only then replaced by<binary>in the log.logbook-servlet–LocalResponse.Teecopies every byte written to the response into aByteArrayOutputStream(large downloads, streaming responses).- Same pattern in
logbook-spring-webflux(DataBufferUtils.join(body)withoutmaxByteCount),logbook-netty(Buffering),logbook-jaxrsandlogbook-jdkserver(ByteStreams.toByteArray).
Why it matters
- The filter runs before the servlet, so the body is buffered even for 404s and for endpoints that never call
getInputStream(). - Tomcat does not limit non-form request bodies by default (
maxPostSizeonly applies to form parameter parsing). - With the Spring Boot starter,
secureLogbookFilterdiscards request bodies (SecurityStrategy) but still buffers response bodies without limit;logbookFilteris exposed on any route reachable without authentication, or everywhere when Spring Security is absent. SecurityStrategy,WithoutBodyStrategyor a customStrategyare only workarounds: they disable body logging entirely.
Reproduction
Minimal test in logbook-servlet: send a 256 MiB body without Content-Length (simulating a chunked upload) through LogbookFilter with an active sink, to a FilterChain that answers 404 without touching the body.
final MockHttpServletRequest request = new MockHttpServletRequest("POST", "/does-not-exist") {
@Override
public ServletInputStream getInputStream() {
return hugeStream; // 256 MiB, never reads Content-Length
}
};
request.setContentType("application/json");
new LogbookFilter(logbook).doFilter(request, new MockHttpServletResponse(),
(req, res) -> ((HttpServletResponse) res).setStatus(404));Observed:
| JVM heap | Result |
|---|---|
-Xmx1g |
all 256 MiB consumed before the chain is invoked, ~767 MiB heap growth |
-Xmx400m |
java.lang.OutOfMemoryError: Java heap space inside the filter |
The same happens with a real curl -T /dev/zero -H 'Transfer-Encoding: chunked' against any Logbook-enabled endpoint when the Logbook logger is at TRACE.
Suggested fix
Bound the amount of body kept in memory, independently of logbook.write.max-body-size (which only truncates after the full read):
- read at most
limit + 1bytes; if the limit is exceeded, hand the already-read prefix plus the remaining stream to the application (SequenceInputStream-likeServletInputStream) and do not log the body; - bound the response
Teethe same way, discarding the copy once the limit is exceeded; - expose the limit on
LogbookFilter/SecureLogbookFilter(e.g.withMaxBufferSize(long)), via a system property for plain servlet users and vialogbook.filter.max-buffer-size(DataSize) for the Spring Boot starter; - pick a secure default (e.g. 1 MiB) with
-1to restore the unbounded behavior; - apply the same bound in the WebFlux (
DataBufferUtils.join(body, maxByteCount)or a copying cap), Netty, JAX-RS and JDK server integrations.
Activity
Vinu2111 commentedon Nov 20, 2026
I have opened PR #2442 addressing this for
logbook-servletandlogbook-spring-boot-autoconfigure.It bounds in-memory buffering for both requests and responses without disrupting downstream stream delivery, backed by 100% line and branch test coverage, keeping
-1(unbounded) as default for backwards compatibility.Bound in-memory request and response buffering in servlet integrations (
Bound in-memory request and response buffering in servlet integrations (