oscerd opened a new pull request, #31316:
URL: https://github.com/apache/camel/pull/31316

   This aligns the shared `fileNameExtWhitelist` upload check in 
`camel-http-base` with the behaviour the option has always advertised.
   
   ## Problem
   
   `HttpHelper.isFileNameExtWhitelisted(whitelist, fileName)` returned `true` 
for any file name with no parseable extension *before* it ever consulted a 
configured whitelist. So when an HTTP consumer set `fileNameExtWhitelist` to a 
concrete list of extensions, a multipart upload whose file name had no 
extension (for example `report`) or was a dot-file (for example `.config`, 
whose single leading dot is treated as a hidden-file marker and not an 
extension) was accepted regardless of the list. That defeats the purpose of the 
option, which is to restrict uploads to the listed extensions.
   
   The check is shared (CAMEL-24652) by the `camel-servlet` and `camel-jetty` 
attachment bindings (through `camel-http-common`'s `DefaultHttpBinding`) and by 
the `camel-platform-http-vertx` consumer, so all of them were affected.
   
   ## Change
   
   `isFileNameExtWhitelisted` is reordered so the whitelist decision is made 
before the extension is consulted:
   
   1. no whitelist configured (`null`) -> accepted;
   2. whitelist is `*` (case-insensitive) -> accepted (everything, including 
names with no extension);
   3. no file name was submitted at all (`null`) -> accepted, as before: this 
is a plain multipart form field and not a file upload, so there is no extension 
to check;
   4. otherwise a file name with no extension (a name with no dot, a dot-file, 
an empty name) -> not accepted (a concrete list is configured and the name 
carries no listed extension);
   5. otherwise the existing exact, case-insensitive, comma-separated token 
match.
   
   `*` and the unset default keep accepting every name, and a listed extension 
is still matched exactly and case-insensitively (never as a substring), so the 
only behaviour that changes is "a file name with no extension under a concrete 
list": it now follows the list instead of being granted up front.
   
   Step 3 matters for the `camel-servlet` and `camel-jetty` attachment 
bindings, which pass every part of a `multipart/form-data` request through the 
check, the plain form fields included (`Part.getSubmittedFileName()` is `null` 
for those). They keep exposing form fields as attachments when a concrete 
whitelist is configured. `camel-platform-http-vertx` only sees file uploads 
there, so it never passes a `null` name.
   
   The method Javadoc and the mirrored Javadoc on 
`DefaultHttpBinding.isFileNameAccepted` are corrected to match. This brings the 
core HTTP consumers in line with the behaviour `camel-platform-http-starter` 
already applies to file uploads.
   
   ## Tests
   
   - `HttpHelperFileNameExtWhitelistTest` in `camel-http-base`: a name with no 
extension, a dot-file and an empty name are rejected under a concrete 
whitelist; a part with no file name is still accepted; a name with no extension 
(and a dot-file) is still accepted when the whitelist is `*` or unset; the 
existing exact-match, substring, multi-dot and case-insensitivity tests are 
unchanged.
   - `DefaultHttpBindingTest` in `camel-http-common`: the test that asserted 
the previous behaviour (`README` accepted under a `txt` whitelist) is updated, 
and split into the three cases above.
   - `MultiPartFormFileNameExtWhitelistTest` in `camel-jetty`: an upload whose 
file name has no extension is not added as an attachment, and a plain form 
field sent next to a whitelisted file is still an attachment.
   
   The test suites of `camel-http-base`, `camel-http-common`, `camel-servlet`, 
`camel-jetty` and `camel-platform-http-vertx` pass with the change.
   
   ## Documentation
   
   An upgrade note is added to the 4.25 upgrade guide, since this is a 
behaviour change for anyone who set `fileNameExtWhitelist`: a name with no 
extension is now rejected while a concrete list is configured; `*` and the 
unset default are unchanged; a part with no file name (a plain form field) is 
handled as before; widen the list explicitly (or use `*`) if uploads without an 
extension are expected.
   
   _Claude Code on behalf of oscerd_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to