Add server.request.body.files_content AppSec address for Undertow and Play#11726
Add server.request.body.files_content AppSec address for Undertow and Play#11726jandro996 wants to merge 5 commits into
Conversation
…Play Implements the files_content WAF address for Undertow 2.0/2.2+ and Play 2.5/2.6. - Undertow: new FormDataContentHelper reads file content via getPath() with reflection fallback for 2.2+ in-memory uploads (getFileItem().getInputStream()) - Play 2.5/2.6: extends BodyParserHelpers with handleMultipartFilesContent(), gated on pendingBlock == null so filenames blocking suppresses content inspection - Content callback fires sequentially after filenames, never if already blocked - Charset-aware decoding via MultipartContentDecoder throughout - MAX_CONTENT_BYTES / MAX_FILES_TO_INSPECT kept in helper classes (not advice) to avoid muzzle failures
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e48784766
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ervers The default limit of 1024 bytes caused RequestTooBigException for the truncation test (4096+500 bytes) and max-files test. Unlimited (-1) allows the content tests to reach the multipart handler.
…ent-undertow-play
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
What Does This Do
Implements the
server.request.body.files_contentWAF address for Undertow 2.0/2.2+ and Play 2.5/2.6, enabling detection and blocking based on the content of uploaded files (not just their names).Undertow 2.0 / 2.2+
FormDataContentHelperreads file content fromFormData.FormValueentries:getPath()first (disk uploads, works in 2.0 and 2.2+)getFileItem().getInputStream()via cached reflection for in-memory uploads (Undertow 2.2+)Headers.CONTENT_TYPEfrom the part headers for charset-aware decoding viaMultipartContentDecoderMultiPartUploadHandlerInstrumentationnow obtainsrequestFilesContentcallback upfront and fires it after the filenames callback, gated ont == null(content is suppressed if filenames already triggered a block)FormDataContentHelperdeclared inhelperClassNames()so constants referencingConfigare kept out of the advice class (avoids muzzle failures)FormDataContentHelperTest: disk file read, form field skip, empty filename, truncation atMAX_CONTENT_BYTES, file count limit, mixed fields+files, graceful fallback for in-memory proxyPlay 2.5 / 2.6
BodyParserHelpersextended withhandleMultipartFilesContent(),collectFilesContent(),readFilePartContent(), andexecuteFilesContentCallback()FilePart.ref()→TemporaryFile.file(), both resolved through cachedstatic final Methodreflection to avoid bytecode references toTemporaryFilethat would break muzzlehandleMultipartFormData()fires only whenpendingBlock == null(sequential: content is suppressed if filenames already blocked)@VisibleForTestingadded to all package-private helper methods (collectFilenames,collectFilesContent,readFilePartContent)Test coverage
UndertowServletTest(2.0 and 2.2):testBodyFilesContent()enabledPlayServerTest(2.5 and 2.6):testBodyFilesContent()enabledPlayAsyncServerTest(2.6):testBodyFilesContent()enabledMotivation
Part of APPSEC-61875 —
server.request.body.files_contentWAF address rollout across Java frameworks. Previous PRs covered commons-fileupload (#11137/#11212), Tomcat+Netty (#11198), and Jersey+RESTEasy (#11229). This PR adds Undertow and Play.Additional Notes
The Undertow 2.0/2.2+ split requires special handling: in 2.0, all uploads are written to disk (
getPath()always succeeds); in 2.2+, small uploads are kept in memory andgetPath()throws. The reflection fallback targetsgetFileItem().getInputStream()which was added in the 2.2+ API. SinceFormDataContentHelperis compiled against the 2.0 API, the method cannot be referenced at compile time.Jira ticket: APPSEC-61875
Note: Once your PR is ready to merge, add it to the merge queue by commenting
/merge./merge -ccancels the queue request./merge -f --reason "reason"skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.