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 ac39e99eb017 CAMEL-24438: camel-platform-http-main - serve static 
content from the configured source directory
ac39e99eb017 is described below

commit ac39e99eb017ea6221e439861cd341efeae938b3
Author: Andrea Cosentino <[email protected]>
AuthorDate: Sun Aug 30 12:26:14 2026 +0200

    CAMEL-24438: camel-platform-http-main - serve static content from the 
configured source directory
    
    When staticSourceDir is configured it now acts as the authoritative source 
for
    static content instead of a fallback consulted only when the working 
directory
    lacks the file. A resolved path that would land outside the configured 
directory
    after canonicalisation is refused, comparing canonical Path values rather 
than
    string prefixes. With no staticSourceDir configured, behaviour is unchanged:
    working directory then class path, per the documented 
prototyping/development
    contract of this option.
    
    The security model's out-of-scope list now documents that serving from the
    class path is this feature's intended contract, not a vulnerability.
    
    Upgrade guide updated to note staticSourceDir is now authoritative when set.
    Adds MainHttpServerStaticTest coverage for path rejection outside the
    configured directory and for a file-system-root configured directory.
    
    Closes #25847
    
    Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
    Co-authored-by: Croway <[email protected]>
---
 .../platform/http/main/MainHttpServer.java         | 33 ++++++++++++---
 .../http/main/MainHttpServerStaticTest.java        | 48 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_23.adoc    | 10 +++++
 .../modules/ROOT/pages/security-model.adoc         | 13 ++++++
 4 files changed, 98 insertions(+), 6 deletions(-)

diff --git 
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
 
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
index 771cddc0f067..dd77c5c6d364 100644
--- 
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
+++ 
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.platform.http.main;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 import io.vertx.core.Handler;
@@ -231,6 +232,26 @@ public class MainHttpServer extends ServiceSupport 
implements CamelContextAware,
         }
     }
 
+    /**
+     * Resolves a request path inside the configured static source directory, 
or returns null when it would land outside
+     * it. Vert.x has already normalised the path, so this is belt-and-braces 
against a name that still escapes once the
+     * file system has had its say (a symlink, or a platform-specific 
separator).
+     */
+    static File containedIn(String dir, String path) {
+        try {
+            File root = new File(dir).getCanonicalFile();
+            File candidate = new File(root, path).getCanonicalFile();
+            if (!candidate.toPath().startsWith(root.toPath())) {
+                LOG.debug("Refusing to serve {}: resolves outside 
staticSourceDir {}", path, dir);
+                return null;
+            }
+            return candidate;
+        } catch (IOException e) {
+            LOG.debug("Unable to resolve {} inside staticSourceDir {}", path, 
dir, e);
+            return null;
+        }
+    }
+
     protected void setupStatic() {
         String path = staticContextPath;
         if (!path.endsWith("*")) {
@@ -252,11 +273,11 @@ public class MainHttpServer extends ServiceSupport 
implements CamelContextAware,
                 }
 
                 InputStream is = null;
-                File f = new File(u);
-                if (!f.exists() && staticSourceDir != null) {
-                    f = new File(staticSourceDir, u);
-                }
-                if (f.exists()) {
+                // When a source dir is configured, serve from it rather than 
falling back to it: resolving
+                // against the process working directory first meant an 
explicitly configured directory was
+                // consulted only for files the working directory did not 
already happen to hold.
+                File f = staticSourceDir != null ? 
containedIn(staticSourceDir, u) : new File(u);
+                if (f != null && f.exists()) {
                     // load directly from file system first
                     try {
                         is = new FileInputStream(f);
@@ -274,7 +295,7 @@ public class MainHttpServer extends ServiceSupport 
implements CamelContextAware,
                     }
                 }
                 if (is != null) {
-                    String mime = 
MimeMapping.getMimeTypeForFilename(f.getName());
+                    String mime = MimeMapping.getMimeTypeForFilename(u);
                     if (mime != null) {
                         ctx.response().putHeader("content-type", mime);
                     }
diff --git 
a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/MainHttpServerStaticTest.java
 
b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/MainHttpServerStaticTest.java
new file mode 100644
index 000000000000..f4d08c560c4c
--- /dev/null
+++ 
b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/MainHttpServerStaticTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.platform.http.main;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class MainHttpServerStaticTest {
+
+    @TempDir
+    Path tempDir;
+
+    @Test
+    void shouldRejectPathOutsideStaticSourceDirectory() {
+        File file = MainHttpServer.containedIn(tempDir.toString(), 
"../outside.html");
+
+        assertThat(file).isNull();
+    }
+
+    @Test
+    void shouldAcceptPathInsideFileSystemRoot() throws IOException {
+        Path root = tempDir.getRoot();
+
+        File file = MainHttpServer.containedIn(root.toString(), "static.html");
+
+        
assertThat(file).isEqualTo(root.resolve("static.html").toFile().getCanonicalFile());
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
index f40ca4dcbd43..29d816b5f233 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
@@ -211,6 +211,16 @@ Applications using either removed option must migrate 
their Tika configuration;
 https://tika.apache.org/docs/4.0.x/migration-to-4x/migrating-to-4x.html[Tika 4 
migration guide] for
 the configuration and metadata-key changes.
 
+=== camel-main / camel-platform-http-main
+
+When `camel.server.staticSourceDir` is configured, static files from the file 
system are now resolved relative to that
+directory instead of first checking the process working directory. The 
configured directory is authoritative, and a
+path that resolves outside it is rejected. Classpath lookup remains unchanged.
+
+Applications that relied on a file in the process working directory taking 
precedence over the configured
+`staticSourceDir` should move that file into the configured directory. 
Applications without a configured
+`staticSourceDir` are unaffected.
+
 === camel-a2a - webhook URL address classification
 
 Push notification webhook URLs are now classified by the address the host 
resolves to, using the
diff --git a/docs/user-manual/modules/ROOT/pages/security-model.adoc 
b/docs/user-manual/modules/ROOT/pages/security-model.adoc
index 83f8034311d8..b282276816df 100644
--- a/docs/user-manual/modules/ROOT/pages/security-model.adoc
+++ b/docs/user-manual/modules/ROOT/pages/security-model.adoc
@@ -885,6 +885,19 @@ be closed as `not a vulnerability`.
   but the CVE itself is closed against the upstream project. See
   https://github.com/apache/camel/blob/main/SECURITY.md[`SECURITY.md`] and the
   upstream project for the actual CVE.
+* *Features whose documented purpose is prototyping and development.* Some
+  conveniences exist to make a local run or a demo easy, and their contract is
+  breadth rather than confinement. `camel.server.staticEnabled` serves static
+  content by resolving the request against the process working directory and
+  then the class path, so that an `html`/`js` file dropped next to the route,
+  or packaged in the jar, is simply served: loading resources from the class
+  path is the point of the option, not an oversight. Running such a feature on
+  an untrusted network is a deployment decision, and the surface it exposes
+  there is operator responsibility. A report is in scope only if the feature
+  behaves outside its own stated contract - for example serving a path outside
+  a directory the operator explicitly configured. Where a component or option
+  is documented as development-oriented, treat that documentation as the
+  contract when triaging.
 * *Self-XSS by an authenticated user* of a UI built on top of Camel.
 * *Reports from automated scanners that do not demonstrate a concrete
   trust-boundary breach.* "Component X uses class Y that has historically had

Reply via email to