Repository navigation
Conversation
…ile uploads UploadedFile.getOriginalName() returns the file name exactly as the client sent it in the multipart Content-Disposition header, including any directory part. The framework itself never uses that value as a path (the stored temp file is always UUID-named), but the legacy FileUploadInterceptor path stripped it via FilenameUtils.getName() before 7.0, and the replacement ActionFileUploadInterceptor/UploadedFilesAware API passes the raw value through unchanged. Adds UploadedFile#getSanitizedOriginalName() (basename only, via FilenameUtils.getName), alongside the existing raw accessor, with javadoc on both making the raw/sanitised distinction explicit. The showcase upload actions, which only ever use the name for display, switch to the sanitised accessor. Tests: AbstractMultiPartRequestTest gains a benign-marker test proving the raw accessor is unsanitised and the new sanitised one is not. Full core suite: 3742/0 failures (includes JakartaMultiPartRequestTest 42/42, JakartaStreamMultiPartRequestTest 43/43). apps/showcase changes are mechanical 1-line accessor swaps with no test asserting the exact filename string; could not run its own suite in this environment due to an unrelated, pre-existing local dependency gap in plugins/tiles (struts2-velocity-tools- view-jakarta never built on this machine), confirmed unrelated to this change by inspection.
lukaszlenart
left a comment
There was a problem hiding this comment.
Thanks for splitting this out of #2115. The approach (a basename accessor next to the raw one, no rejection of names) is the one we want. A few things before merge:
-
@since 7.5.0should be@since 7.6.0. 7.5.0 and 7.5.1 are already released; WW-5840 targets 7.6.0. -
The Javadoc of
getSanitizedOriginalName()promises more than a basename strip delivers. It says the result is suitable "for building a path under an application-controlled directory", butFilenameUtils.getNamereturns..unchanged and turnsa/b/into an empty string, sonew File(dir, getSanitizedOriginalName())can still resolve todiritself or its parent. That contradicts the "must not be used to build a filesystem path" note ongetOriginalName()just above. Suggested wording: basename only, intended for display; validate it before using it in a filesystem path. The namegetSanitized...also suggests more validation than the method performs. Something likegetOriginalBaseName()would describe it more precisely. Worth settling now, since this becomes public API. -
Please trim the comments.
- The new method is one line, but its Javadoc runs to ~20 lines, most of it history (the pre-7.0
getFileNames()/getCanonicalName()pair, "has no caller in the current flow"). That context belongs in the PR description and commit message. In the Javadoc, two or three lines saying what it returns and what it doesn't guarantee are enough. - The four-line comment in the
ActionFileUploadInterceptorexample can be a single line. - In the test, the Javadoc block and the
// Fix:/// Control:narration can go. The assertions read fine on their own.
- The new method is one line, but its Javadoc runs to ~20 lines, most of it history (the pre-7.0
-
Minor: please add a Windows-style case to the test. WW-5840 mentions backslash-separated paths. One more assertion, e.g. an original name of
C:\x\y.txtgivingy.txt, would cover that.
I ran JakartaMultiPartRequestTest and JakartaStreamMultiPartRequestTest locally against this branch, and the new test passes with both parsers.
|
Thanks for the review. Pushed b6961fd addressing all four points:
Full core suite passes locally (3742 run, 0 failures). |
Fixes WW-5840
UploadedFile.getOriginalName()returns the file name exactly as the client sent it, including any directory part. The framework itself never uses that value as a path (the stored temp file is always UUID-named). The legacy pre-7.0getFileNames()/getCanonicalName()pair onMultiPartRequeststripped the directory part, but the replacementActionFileUploadInterceptor/UploadedFilesAwareAPI passes the raw value through unchanged and has no basename accessor.UploadedFile#getOriginalBaseName()(@since 7.6.0), a default method returning the last path segment viaFilenameUtils.getName, alongside the raw accessor. It is for display only: the result may still be empty or.., so it must be validated before use in a filesystem path.Verified:
AbstractMultiPartRequestTestgains a test covering../evil.csvand the Windows-styleC:\x\y.txt(raw accessor unchanged, basename accessor returnsevil.csv/y.txt). Fullcoresuite: 3742 run, 0 failures, 0 errors.apps/showcasechanges are one-token accessor swaps; its module could not be built locally because of an unrelated offline plugin-resolution gap.