Lukasz Lenart created WW-5853:
---------------------------------

             Summary: REST plugin skips a chunked request body: 
ContentTypeInterceptor reads the body only when getContentLength() is positive
                 Key: WW-5853
                 URL: https://issues.apache.org/jira/browse/WW-5853
             Project: Struts 2
          Issue Type: Bug
          Components: Plugin - REST
    Affects Versions: 7.4.0, 6.12.0
            Reporter: Lukasz Lenart


{{ContentTypeInterceptor.intercept}} reads and binds the request body only 
inside {{if (request.getContentLength() > 0)}}. A request sent with 
{{Transfer-Encoding: chunked}} has no {{Content-Length}}, so 
{{getContentLength()}} returns {{-1}} and the whole branch is skipped: the body 
is never read, no handler runs, the action sees no body fields and the request 
typically fails validation (HTTP 400 in {{rest-showcase}}). Nothing is logged.

h2. Where

{{plugins/rest/src/main/java/org/apache/struts2/rest/ContentTypeInterceptor.java}},
 the {{getContentLength() > 0}} gate around the {{BoundedReader}} / 
{{applyRequestBody}} block. The gate predates the body size limit 
({{struts.rest.content.maxLength}}) and is identical on {{main}} and 
{{support/struts-6-x-x}}.

h2. Fix

Treat a request as having a body when the content length is positive *or* the 
request is chunked ({{getContentLength() == -1}} with a {{Transfer-Encoding}} 
header, or simply when the content type is one the plugin handles and the 
reader is non-empty). The body must still go through {{BoundedReader}} with 
{{struts.rest.content.maxLength}}, because a chunked body has no declared 
length; the bound is the only protection against an oversized body and must not 
be weakened by this fix.

Add tests to {{ContentTypeInterceptorTest}}: a {{MockHttpServletRequest}} with 
content length {{-1}}, {{Transfer-Encoding: chunked}} and a JSON body is bound; 
the same request with a body over {{maxLength}} is rejected the same way a 
{{Content-Length}} request is.

h2. Source

Reported publicly on the Full Disclosure list, 2026-10-29: 
https://seclists.org/fulldisclosure/2026/Nov/2



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to