This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new e770037ade3f CAMEL-27928: camel-http-base - fileNameExtWhitelist
rejects file names with no extension (#31316)
e770037ade3f is described below
commit e770037ade3f3e82051314a65d1eca5bc8b59180
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Dec 3 14:25:47 2026 +0100
CAMEL-27928: camel-http-base - fileNameExtWhitelist rejects file names with
no extension (#31316)
* CAMEL-27928: camel-http-base - fileNameExtWhitelist rejects file names
with no extension
The shared fileNameExtWhitelist check accepted a file name with no
extension before it consulted a configured whitelist, so a concrete
list did not restrict uploads whose name had no extension or was a
dot-file. The check now decides the whitelist states first: no
whitelist or * still accept every name, while a concrete list rejects
a name with no extension. The method Javadoc and the mirrored Javadoc
on DefaultHttpBinding are corrected to match.
* CAMEL-27928: camel-http-base - a multipart part with no file name is not
a file upload
A multipart part that carries no file name, such as a plain form field,
is not a file upload, so the fileNameExtWhitelist check keeps accepting
it and the servlet and jetty bindings keep exposing form fields as
attachments when a concrete whitelist is configured. A file name with no
extension is still rejected. The camel-http-common binding test is
aligned with this behaviour, and the jetty multipart test covers a file
name with no extension and a form field next to a whitelisted file.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Andrea Cosentino <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
.../org/apache/camel/http/base/HttpHelper.java | 23 ++++++++-----
.../base/HttpHelperFileNameExtWhitelistTest.java | 38 ++++++++++++++++++++--
.../camel/http/common/DefaultHttpBinding.java | 7 ++--
.../camel/http/common/DefaultHttpBindingTest.java | 20 +++++++++++-
.../MultiPartFormFileNameExtWhitelistTest.java | 34 ++++++++++++++++++-
.../ROOT/pages/camel-4x-upgrade-guide-4_25.adoc | 15 +++++++++
6 files changed, 121 insertions(+), 16 deletions(-)
diff --git
a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpHelper.java
b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpHelper.java
index 4ef655fe84e5..ad7a7ab3ece3 100644
---
a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpHelper.java
+++
b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpHelper.java
@@ -294,26 +294,33 @@ public final class HttpHelper {
* <p/>
* The file name extension is compared, case-insensitively, against each
comma-separated entry of the whitelist
* exactly and not as a substring: a whitelist of {@code txt} must not
accept an upload named {@code evil.x} just
- * because {@code "txt".contains("x")}. A file is accepted when no
whitelist is configured, when the whitelist is
- * {@code *}, or when the file name has no extension. The configured
whitelist value is not modified.
+ * because {@code "txt".contains("x")}. A file is accepted when no
whitelist is configured or when the whitelist is
+ * {@code *}; when a concrete whitelist is configured, a file name with no
extension is not accepted. A {@code null}
+ * file name means that no file name was submitted, as for a plain
multipart form field: that is not a file upload,
+ * so there is no extension to check and it is accepted. The configured
whitelist value is not modified.
*
* @param whitelist the configured {@code fileNameExtWhitelist} (may be
{@code null})
- * @param fileName the file name submitted by the client
+ * @param fileName the file name submitted by the client (may be {@code
null} when the part carries none)
* @return true if the file is accepted
*/
public static boolean isFileNameExtWhitelisted(String whitelist, String
fileName) {
if (whitelist == null) {
return true;
}
- String ext = FileUtil.onlyExt(fileName);
- if (ext == null) {
- return true;
- }
- ext = ext.toLowerCase(Locale.US);
String lcWhitelist = whitelist.toLowerCase(Locale.US);
if (lcWhitelist.equals("*")) {
return true;
}
+ if (fileName == null) {
+ // no file name was submitted, so this is not a file upload (the
servlet and jetty bindings also pass
+ // the plain form fields of a multipart request through here) and
there is no extension to check
+ return true;
+ }
+ String ext = FileUtil.onlyExt(fileName);
+ if (ext == null) {
+ return false;
+ }
+ ext = ext.toLowerCase(Locale.US);
for (String allowed : lcWhitelist.split(",")) {
if (allowed.trim().equals(ext)) {
return true;
diff --git
a/components/camel-http-base/src/test/java/org/apache/camel/http/base/HttpHelperFileNameExtWhitelistTest.java
b/components/camel-http-base/src/test/java/org/apache/camel/http/base/HttpHelperFileNameExtWhitelistTest.java
index b6ab8eec7eed..d739856d11a9 100644
---
a/components/camel-http-base/src/test/java/org/apache/camel/http/base/HttpHelperFileNameExtWhitelistTest.java
+++
b/components/camel-http-base/src/test/java/org/apache/camel/http/base/HttpHelperFileNameExtWhitelistTest.java
@@ -24,7 +24,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests for the shared {@code fileNameExtWhitelist} check used by the HTTP
bindings and the platform-http-vertx
* consumer (CAMEL-24652). The important property is that an extension is
matched as a whole comma-separated token and
- * never as a substring of the whitelist.
+ * never as a substring of the whitelist. A concrete whitelist also rejects a
file name with no extension, while
+ * {@code *} and an unset whitelist accept everything. A part with no file
name at all is not a file upload and is
+ * accepted.
*/
class HttpHelperFileNameExtWhitelistTest {
@@ -39,8 +41,38 @@ class HttpHelperFileNameExtWhitelistTest {
}
@Test
- void aNameWithoutAnExtensionIsAccepted() {
- assertTrue(HttpHelper.isFileNameExtWhitelisted("txt", "noextension"));
+ void aNameWithoutAnExtensionIsRejectedWhenAWhitelistIsConfigured() {
+ assertFalse(HttpHelper.isFileNameExtWhitelisted("txt", "noextension"));
+ }
+
+ @Test
+ void aDotFileIsRejectedWhenAWhitelistIsConfigured() {
+ // a leading dot is treated as a hidden file, not an extension, so it
is not on a concrete whitelist
+ assertFalse(HttpHelper.isFileNameExtWhitelisted("txt", ".config"));
+ assertFalse(HttpHelper.isFileNameExtWhitelisted("txt", ".dotfile"));
+ }
+
+ @Test
+ void anEmptyNameIsRejectedWhenAWhitelistIsConfigured() {
+ // a file part that was submitted with an empty file name carries no
extension either
+ assertFalse(HttpHelper.isFileNameExtWhitelisted("txt", ""));
+ }
+
+ @Test
+ void aPartWithoutAFileNameIsAcceptedWhenAWhitelistIsConfigured() {
+ // no file name was submitted, as for a plain multipart form field, so
this is not a file upload
+ assertTrue(HttpHelper.isFileNameExtWhitelisted("txt", null));
+ }
+
+ @Test
+ void aNameWithoutAnExtensionIsAcceptedWhenNoWhitelistIsConfigured() {
+ assertTrue(HttpHelper.isFileNameExtWhitelisted(null, "noextension"));
+ }
+
+ @Test
+ void aNameWithoutAnExtensionIsAcceptedWhenTheWhitelistIsStar() {
+ assertTrue(HttpHelper.isFileNameExtWhitelisted("*", "noextension"));
+ assertTrue(HttpHelper.isFileNameExtWhitelisted("*", ".config"));
}
@Test
diff --git
a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
index 4b4e1b944cad..7ec4f381334f 100644
---
a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
+++
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
@@ -390,10 +390,11 @@ public class DefaultHttpBinding implements HttpBinding {
* <p/>
* The file name extension is compared, case-insensitively, against each
comma-separated entry of the whitelist
* exactly and not as a substring: a whitelist of "txt" must not accept an
upload named "evil.x" just because
- * "txt".contains("x"). A file is accepted when no whitelist is
configured, when the whitelist is "*", or when the
- * file name has no extension.
+ * "txt".contains("x"). A file is accepted when no whitelist is configured
or when the whitelist is "*"; when a
+ * concrete whitelist is configured, a file name with no extension is not
accepted. A null file name means that no
+ * file name was submitted, as for a plain multipart form field: that is
not a file upload and it is accepted.
*
- * @param fileName the file name submitted by the client
+ * @param fileName the file name submitted by the client (may be null
when the part carries none)
* @return true if the file is accepted
*/
protected boolean isFileNameAccepted(String fileName) {
diff --git
a/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java
b/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java
index 8809c9b8ed8c..ee69c157ca9b 100644
---
a/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java
+++
b/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java
@@ -81,11 +81,29 @@ public class DefaultHttpBindingTest extends
CamelTestSupport {
}
@Test
- public void testFileNameAcceptedWithoutExtension() {
+ public void testFileNameWithoutExtensionIsNotAcceptedWithWhitelist() {
DefaultHttpBinding binding = new DefaultHttpBinding();
binding.setFileNameExtWhitelist("txt");
+ assertFalse(binding.isFileNameAccepted("README"));
+ assertFalse(binding.isFileNameAccepted(".config"));
+ }
+
+ @Test
+ public void
testFileNameWithoutExtensionIsAcceptedWithoutWhitelistOrWithWildcard() {
+ DefaultHttpBinding binding = new DefaultHttpBinding();
+ assertTrue(binding.isFileNameAccepted("README"));
+
+ binding.setFileNameExtWhitelist("*");
assertTrue(binding.isFileNameAccepted("README"));
+ }
+
+ @Test
+ public void testPartWithoutFileNameIsAcceptedWithWhitelist() {
+ DefaultHttpBinding binding = new DefaultHttpBinding();
+ binding.setFileNameExtWhitelist("txt");
+
+ // no file name was submitted, as for a plain multipart form field, so
this is not a file upload
assertTrue(binding.isFileNameAccepted(null));
}
diff --git
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormFileNameExtWhitelistTest.java
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormFileNameExtWhitelistTest.java
index a8ae1d0a55c5..b2d2d5c46539 100644
---
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormFileNameExtWhitelistTest.java
+++
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormFileNameExtWhitelistTest.java
@@ -39,6 +39,7 @@ public class MultiPartFormFileNameExtWhitelistTest extends
BaseJettyTest {
private static final String FIELD_NAME = "upload";
private static final String FILE_NAME = "log4j2.properties";
+ private static final String TEXT_FIELD_NAME = "comment";
@Test
public void testUploadAcceptedWhenExtensionIsWhitelisted() {
@@ -58,11 +59,34 @@ public class MultiPartFormFileNameExtWhitelistTest extends
BaseJettyTest {
assertThat(upload("/substring")).isEqualTo("attachment=false,headerIsAttachment=false,fileNameHeader=false");
}
- private String upload(String path) {
+ @Test
+ public void testUploadRejectedWhenFileNameHasNoExtension() {
+ // the whitelist lists "properties", and a file name with no extension
is not on it
+ assertThat(upload("/allowed", "README"))
+
.isEqualTo("attachment=false,headerIsAttachment=false,fileNameHeader=false");
+ }
+
+ @Test
+ public void testFormFieldWithoutFileNameIsKeptWhenAWhitelistIsConfigured()
{
+ // a plain form field carries no file name, so it is not a file upload
and the whitelist leaves it alone
File file = new File("src/test/resources/log4j2.properties");
HttpEntity entity = MultipartEntityBuilder.create()
+ .addTextBody(TEXT_FIELD_NAME, "A binary file of some kind")
.addBinaryBody(FIELD_NAME, file,
ContentType.APPLICATION_OCTET_STREAM, FILE_NAME)
.build();
+ String result = template.requestBody("http://localhost:" + getPort() +
"/field", entity, String.class);
+ assertThat(result).isEqualTo("field=true,attachment=true");
+ }
+
+ private String upload(String path) {
+ return upload(path, FILE_NAME);
+ }
+
+ private String upload(String path, String fileName) {
+ File file = new File("src/test/resources/log4j2.properties");
+ HttpEntity entity = MultipartEntityBuilder.create()
+ .addBinaryBody(FIELD_NAME, file,
ContentType.APPLICATION_OCTET_STREAM, fileName)
+ .build();
return template.requestBody("http://localhost:" + getPort() + path,
entity, String.class);
}
@@ -78,6 +102,8 @@ public class MultiPartFormFileNameExtWhitelistTest extends
BaseJettyTest {
.process(MultiPartFormFileNameExtWhitelistTest::reportAttachment);
from(whitelisted("/substring", "propertiesx"))
.process(MultiPartFormFileNameExtWhitelistTest::reportAttachment);
+ from(whitelisted("/field", "properties"))
+
.process(MultiPartFormFileNameExtWhitelistTest::reportFormField);
}
private JettyHttpEndpoint whitelisted(String path, String
whitelist) {
@@ -98,4 +124,10 @@ public class MultiPartFormFileNameExtWhitelistTest extends
BaseJettyTest {
+ ",headerIsAttachment=" + (attachment
!= null && headerByField == attachment)
+ ",fileNameHeader=" +
(in.getHeader(FILE_NAME) != null));
}
+
+ private static void reportFormField(Exchange exchange) {
+ AttachmentMessage in = exchange.getIn(AttachmentMessage.class);
+ exchange.getMessage().setBody("field=" +
(in.getAttachment(TEXT_FIELD_NAME) != null)
+ + ",attachment=" +
(in.getAttachment(FIELD_NAME) != null));
+ }
}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
index 02f5fa9cdcd6..5c8f75a17a97 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
@@ -44,6 +44,21 @@ and leaves out `Access-Control-Allow-Credentials`. Camel
logs a WARN when the ro
configure the allowed origin, for example
`corsHeaderProperty("Access-Control-Allow-Origin", "https://app.example.com")`.
This matches what `platform-http-vertx` and `camel-a2a` already do.
+=== camel-servlet, camel-jetty, camel-platform-http-vertx -
fileNameExtWhitelist rejects file names with no extension
+
+The `fileNameExtWhitelist` option of the HTTP consumers (`camel-servlet`,
`camel-jetty` and
+`camel-platform-http-vertx`) restricts multipart uploads to the file name
extensions listed in it. When a
+concrete list was configured, an upload whose file name had no extension (for
example `report`) or was a
+dot-file (for example `.config`) was still accepted, because the shared check
treated a name with no extension
+as a match. The shared check now rejects a file name with no extension while a
concrete list is configured. An
+unset list and `*` still accept every upload, and a listed extension is
matched exactly and case-insensitively
+as before. A multipart part that carries no file name at all, such as a plain
form field, is not a file upload
+and is handled as before.
+
+A consumer that set `fileNameExtWhitelist` and relied on uploads with no
extension passing through should
+widen the list explicitly, for example by adding the expected extensions or by
using `*` to accept every name.
+This matches the behaviour already applied by `camel-platform-http-starter`.
+
=== camel-langchain4j-agent - deprecate response model header
The `CamelLangChain4jAgentResponseModel` header is now deprecated because the
LangChain4j agent `Result` does not expose the response model name. The
producer did not populate this header, so applications should not rely on it.