This is an automated email from the ASF dual-hosted git repository.

oscerd pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new 67f7ea7465a1 [backport camel-4.18.x] CAMEL-23515: camel-nats - Use 
dedicated HeaderFilterStrategy aligned with sibling components
67f7ea7465a1 is described below

commit 67f7ea7465a1bf637339975c69a82327890e22f0
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon May 18 09:15:53 2026 +0200

    [backport camel-4.18.x] CAMEL-23515: camel-nats - Use dedicated 
HeaderFilterStrategy aligned with sibling components
    
    Backport of #23233 onto camel-4.18.x. camel-nats defaulted its
    headerFilterStrategy to a bare DefaultHeaderFilterStrategy, passing every
    inbound NATS header (including Camel* / camel* / org.apache.camel.*) onto
    the Exchange. Introduces NatsHeaderFilterStrategy (KafkaHeaderFilterStrategy
    / MailHeaderFilterStrategy shape) and switches the default to it, aligning
    camel-nats with the rest of the component catalog. Includes a unit test and
    the camel-4x-upgrade-guide-4_18.adoc note.
    
    (cherry picked from commit be8aad96fa04f81d2b58884e27ba6755c9ad2718)
    
    JIRA: https://issues.apache.org/jira/browse/CAMEL-23515
    
    Closes #23250
---
 .../camel/component/nats/NatsConfiguration.java    |  3 +-
 .../component/nats/NatsHeaderFilterStrategy.java   | 34 ++++++++++++++
 .../nats/NatsHeaderFilterStrategyTest.java         | 53 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_18.adoc    |  7 +++
 4 files changed, 95 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
 
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
index ea2fa55136a5..26a66d732942 100644
--- 
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
+++ 
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
@@ -29,7 +29,6 @@ import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
-import org.apache.camel.support.DefaultHeaderFilterStrategy;
 import org.apache.camel.support.jsse.SSLContextParameters;
 import org.apache.camel.util.ObjectHelper;
 
@@ -114,7 +113,7 @@ public class NatsConfiguration implements Cloneable {
     @UriParam(label = "advanced")
     private boolean traceConnection;
     @UriParam(label = "advanced")
-    private HeaderFilterStrategy headerFilterStrategy = new 
DefaultHeaderFilterStrategy();
+    private HeaderFilterStrategy headerFilterStrategy = new 
NatsHeaderFilterStrategy();
 
     public NatsConfiguration copy() {
         try {
diff --git 
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsHeaderFilterStrategy.java
 
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsHeaderFilterStrategy.java
new file mode 100644
index 000000000000..9997b3a66623
--- /dev/null
+++ 
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsHeaderFilterStrategy.java
@@ -0,0 +1,34 @@
+/*
+ * 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.nats;
+
+import org.apache.camel.support.DefaultHeaderFilterStrategy;
+
+public class NatsHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
+
+    public NatsHeaderFilterStrategy() {
+        initialize();
+    }
+
+    protected void initialize() {
+        setLowerCase(true);
+        // filter headers begin with "Camel" or "org.apache.camel"
+        setOutFilterStartsWith(CAMEL_FILTER_STARTS_WITH);
+        setInFilterStartsWith(CAMEL_FILTER_STARTS_WITH);
+    }
+
+}
diff --git 
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsHeaderFilterStrategyTest.java
 
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsHeaderFilterStrategyTest.java
new file mode 100644
index 000000000000..96083045a0db
--- /dev/null
+++ 
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsHeaderFilterStrategyTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.nats;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class NatsHeaderFilterStrategyTest {
+
+    private final NatsHeaderFilterStrategy strategy = new 
NatsHeaderFilterStrategy();
+
+    @Test
+    void inboundCamelHeadersAreFiltered() {
+        assertTrue(strategy.applyFilterToExternalHeaders("CamelHttpUri", 
"http://evil.example";, null));
+        assertTrue(strategy.applyFilterToExternalHeaders("CamelFileName", 
"../../etc/passwd", null));
+        
assertTrue(strategy.applyFilterToExternalHeaders("CamelBeanMethodName", 
"evilMethod", null));
+    }
+
+    @Test
+    void inboundLowercaseCamelHeadersAreFiltered() {
+        assertTrue(strategy.applyFilterToExternalHeaders("camelHttpUri", 
"http://evil.example";, null));
+        assertTrue(strategy.applyFilterToExternalHeaders("camelfilename", 
"../../etc/passwd", null));
+    }
+
+    @Test
+    void outboundCamelHeadersAreFiltered() {
+        assertTrue(strategy.applyFilterToCamelHeaders("CamelHttpUri", "value", 
null));
+        assertTrue(strategy.applyFilterToCamelHeaders("camelHttpUri", "value", 
null));
+    }
+
+    @Test
+    void nonCamelHeadersPassThrough() {
+        assertFalse(strategy.applyFilterToExternalHeaders("Content-Type", 
"application/json", null));
+        assertFalse(strategy.applyFilterToExternalHeaders("X-Request-Id", 
"abc-123", null));
+        assertFalse(strategy.applyFilterToCamelHeaders("Content-Type", 
"application/json", null));
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc
index d98707335f29..bae55ac54afd 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc
@@ -278,6 +278,13 @@ Two new endpoint options have been added to control the 
pull fetch loop:
 * `pullBatchSize` (default `10`) — maximum number of messages to fetch per 
pull request.
 * `pullFetchTimeout` (default `1000` ms) — maximum time to wait for a batch on 
each fetch.
 
+The default `headerFilterStrategy` is now a new `NatsHeaderFilterStrategy` 
that filters headers
+starting with `Camel` / `camel` (case-insensitive) in both the inbound and 
outbound directions,
+aligning the component with the rest of the Camel component catalog 
(`camel-kafka`, `camel-mail`,
+`camel-coap`, `camel-google-pubsub`, ...). Routes that relied on passing 
through these header
+names from NATS messages can supply a custom `headerFilterStrategy` to restore 
the previous
+behaviour.
+
 === camel-couchdb
 
 The Exchange header values exposed by `CouchDbConstants` have been renamed to 
follow the standard

Reply via email to