Add formParamsMaxSize to FormEncodingProvider and estimate form params count before decoding / parsing - #3444
Conversation
…s count before decoding / parsing
5a82585 to
77a6939
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new early part-count estimation and the new large-body systest have correctness/robustness issues that should be addressed before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR introduces configurable limits for JAX-RS application/x-www-form-urlencoded request handling by adding a maximum form-body size configuration to FormEncodingProvider, and by adding an early estimate of form parameter count before splitting/decoding to mitigate excessive input.
Changes:
- Add
formParamsMaxSizetoFormEncodingProviderand enforce it when reading the request body. - Add a system-property-backed default max form-body size in
FormUtils, plus a newreadBody(..., maxSize)overload. - Add systests covering “too many form params” and “too large form body”.
File summaries
| File | Description |
|---|---|
| systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java | Adds systests for form param count and form body size limit scenarios. |
| rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java | Adds default max form size, a size-limited body reader, and an early param-count estimate prior to splitting/decoding. |
| rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java | Adds configurable formParamsMaxSize and uses it when reading form bodies. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@reta Can you check these comments please: High: the vulnerable @FormParam path remains unchanged. The PR limits reads only inside FormEncodingProvider. However, ordinary @FormParam processing is handled directly by JAXRSUtils.processFormParam, which still does: FormUtils.readBody(entityStream, enc) using the uncapped overload. JAXRSUtils.java:1201 The servlet request adapter has the same issue: HttpServletRequestFilter.java:122 The changed provider path now calls the capped overload, but its default is 100 MiB. readBody materializes the body into a ByteArrayOutputStream, then creates another byte array with toByteArray(), and then creates a decoded String. A request near the configured limit can therefore require substantially more than 100 MiB of transient memory before the parser rejects it. Also, IOUtils.copy writes the input chunk before checking whether maxSize has been exceeded: IOUtils.java:218 |
Thanks @coheigea . yes, I am going through though form param handling, starting with |
Add
formParamsMaxSizetoFormEncodingProviderand estimate form params count before decoding / parsing