oscerd commented on code in PR #27945:
URL: https://github.com/apache/camel/pull/27945#discussion_r4311319323


##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java:
##########
@@ -218,7 +218,11 @@ protected void channelRead0(ChannelHandlerContext ctx, 
Object msg) throws Except
     }
 
     private String extractTarget(URI uri) {
-        String target = uri.getPath();
+        // resolve any . and .. segments first, so the security constraint is 
evaluated against the
+        // effective resolved resource path and not the raw request path. 
Without this a request such
+        // as /foo/../admin/x (or its percent-encoded /foo/%2e%2e/admin/x 
form) is matched against the
+        // inclusions in its unresolved form and can evade a constraint that 
guards /admin/* (CAMEL-25705)
+        String target = removeDotSegments(uri.getPath());

Review Comment:
   You're both right — resolving only the ACL target left the consumer dispatch 
(`HttpServerMultiplexChannelHandler.getHandler` on the raw `request.uri()`) and 
the route (`CamelHttpPath` from `getRawPath`) on the raw path, so the 
constraint and the route could still disagree. It even opened a reverse case: 
`/foo/admin/../public/x` resolved to the excluded `/public/x`, while the raw 
form matched the `/admin/*` inclusion.
   
   Changed direction to option (a): when a `securityConstraint` is configured, 
a request whose path carries `.`/`..` segments (including the `%2e` form) is 
now rejected with **HTTP 400** up front — before the route runs — so the 
constraint, dispatch and the route all act on the same dot-segment-free path. 
This matches Spring's `StrictHttpFirewall`, and a well-behaved client 
normalizes dot-segments before sending. `extractTarget` is back to the raw 
path; `removeDotSegments` is now only used to detect the segments.
   
   _Claude Code on behalf of oscerd_
   



##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java:
##########
@@ -218,7 +218,11 @@ protected void channelRead0(ChannelHandlerContext ctx, 
Object msg) throws Except
     }
 
     private String extractTarget(URI uri) {
-        String target = uri.getPath();
+        // resolve any . and .. segments first, so the security constraint is 
evaluated against the
+        // effective resolved resource path and not the raw request path. 
Without this a request such

Review Comment:
   You're both right — resolving only the ACL target left the consumer dispatch 
(`HttpServerMultiplexChannelHandler.getHandler` on the raw `request.uri()`) and 
the route (`CamelHttpPath` from `getRawPath`) on the raw path, so the 
constraint and the route could still disagree. It even opened a reverse case: 
`/foo/admin/../public/x` resolved to the excluded `/public/x`, while the raw 
form matched the `/admin/*` inclusion.
   
   Changed direction to option (a): when a `securityConstraint` is configured, 
a request whose path carries `.`/`..` segments (including the `%2e` form) is 
now rejected with **HTTP 400** up front — before the route runs — so the 
constraint, dispatch and the route all act on the same dot-segment-free path. 
This matches Spring's `StrictHttpFirewall`, and a well-behaved client 
normalizes dot-segments before sending. `extractTarget` is back to the raw 
path; `removeDotSegments` is now only used to detect the segments.
   
   _Claude Code on behalf of oscerd_
   



##########
components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthConstraintDotSegmentTest.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.netty.http;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.test.junit6.TestSupport.assertIsInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * A request containing . or .. segments is routed to the consumer without 
resolving those segments, so the security
+ * constraint has to be evaluated against the effective resolved path. 
Otherwise a request such as /foo/../admin/x (or
+ * its percent-encoded /foo/%2e%2e/admin/x form) reaches the route while 
skipping the constraint that guards /admin/*.
+ */
+class NettyHttpBasicAuthConstraintDotSegmentTest extends BaseNettyTestSupport {
+
+    @Override
+    public void doPreSetup() {
+        System.setProperty("java.security.auth.login.config", 
"src/test/resources/myjaas.config");
+    }
+
+    @Override
+    public void doPostTearDown() {
+        System.clearProperty("java.security.auth.login.config");
+    }
+
+    @BindToRegistry("mySecurityConfig")
+    public NettyHttpSecurityConfiguration loadSecConf() {
+        NettyHttpSecurityConfiguration security = new 
NettyHttpSecurityConfiguration();
+        security.setRealm("karaf");
+        SecurityAuthenticator auth = new JAASSecurityAuthenticator();
+        auth.setName("karaf");
+        security.setSecurityAuthenticator(auth);
+
+        // a specific inclusion, not a catch-all: only /admin/* below the 
endpoint path is restricted
+        SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+        matcher.addInclusion("/admin/*");
+        security.setSecurityConstraint(matcher);
+
+        return security;
+    }
+
+    @Test
+    void plainPathIsChallenged() {
+        assertChallenged("netty-http:http://localhost:{{port}}/foo/admin/x";);
+    }
+
+    @Test
+    void literalDotSegmentIsChallenged() {
+        // without resolving the .. the constraint target is /../admin/x, 
which matches no inclusion
+        
assertChallenged("netty-http:http://localhost:{{port}}/foo/../admin/x";);

Review Comment:
   Addressed. The end-to-end test now configures `/admin/*` (inclusion) + 
`/public/*` (exclusion) and asserts **400** for: the leading `..` 
(`/foo/../admin/x`), the encoded `/foo/%2e%2e/admin/x`, an in-context traversal 
(`/foo/x/../admin/y`, which stays under `/foo`), and the reverse case 
(`/foo/admin/../public/x`). It keeps two controls: a restricted path → 401 and 
the excluded path → 200. So the coverage no longer relies on the out-of-context 
coincidence.
   
   _Claude Code on behalf of oscerd_
   



##########
components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthConstraintDotSegmentTest.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.netty.http;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.test.junit6.TestSupport.assertIsInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * A request containing . or .. segments is routed to the consumer without 
resolving those segments, so the security
+ * constraint has to be evaluated against the effective resolved path. 
Otherwise a request such as /foo/../admin/x (or
+ * its percent-encoded /foo/%2e%2e/admin/x form) reaches the route while 
skipping the constraint that guards /admin/*.
+ */
+class NettyHttpBasicAuthConstraintDotSegmentTest extends BaseNettyTestSupport {
+
+    @Override
+    public void doPreSetup() {
+        System.setProperty("java.security.auth.login.config", 
"src/test/resources/myjaas.config");
+    }
+
+    @Override
+    public void doPostTearDown() {
+        System.clearProperty("java.security.auth.login.config");
+    }
+
+    @BindToRegistry("mySecurityConfig")
+    public NettyHttpSecurityConfiguration loadSecConf() {
+        NettyHttpSecurityConfiguration security = new 
NettyHttpSecurityConfiguration();
+        security.setRealm("karaf");
+        SecurityAuthenticator auth = new JAASSecurityAuthenticator();
+        auth.setName("karaf");
+        security.setSecurityAuthenticator(auth);
+
+        // a specific inclusion, not a catch-all: only /admin/* below the 
endpoint path is restricted
+        SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+        matcher.addInclusion("/admin/*");
+        security.setSecurityConstraint(matcher);
+
+        return security;
+    }
+
+    @Test
+    void plainPathIsChallenged() {
+        assertChallenged("netty-http:http://localhost:{{port}}/foo/admin/x";);
+    }
+
+    @Test
+    void literalDotSegmentIsChallenged() {
+        // without resolving the .. the constraint target is /../admin/x, 
which matches no inclusion
+        
assertChallenged("netty-http:http://localhost:{{port}}/foo/../admin/x";);

Review Comment:
   Addressed. The end-to-end test now configures `/admin/*` (inclusion) + 
`/public/*` (exclusion) and asserts **400** for: the leading `..` 
(`/foo/../admin/x`), the encoded `/foo/%2e%2e/admin/x`, an in-context traversal 
(`/foo/x/../admin/y`, which stays under `/foo`), and the reverse case 
(`/foo/admin/../public/x`). It keeps two controls: a restricted path → 401 and 
the excluded path → 200. So the coverage no longer relies on the out-of-context 
coincidence.
   
   _Claude Code on behalf of oscerd_
   



##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc:
##########
@@ -523,6 +523,21 @@ registered.
 To restore the previous behaviour, set `webhookSecretTokenEnabled=false`: the 
webhook is then registered without a
 secret token, and webhook requests are not verified.
 
+=== camel-netty-http - the security constraint resolves dot-segments in the 
request path
+
+A `netty-http` consumer configured with a `securityConstraint` now resolves 
`.` and `..` segments in the request path
+(including their percent-encoded `%2e` form) before the path is matched 
against the configured inclusions and exclusions,
+following the `remove_dot_segments` algorithm of RFC 3986. The constraint is 
therefore evaluated against the effective
+resolved path, which is the same resource the request is routed to. Excess 
`..` segments cannot climb above the root.

Review Comment:
   Fixed. The guide entry is rewritten for the new behavior — a request path 
with dot-segments is rejected with 400 when a `securityConstraint` is 
configured — and the "same resource the request is routed to" claim is removed, 
since the route receives the raw path.
   
   _Claude Code on behalf of oscerd_
   



##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc:
##########
@@ -523,6 +523,21 @@ registered.
 To restore the previous behaviour, set `webhookSecretTokenEnabled=false`: the 
webhook is then registered without a
 secret token, and webhook requests are not verified.
 
+=== camel-netty-http - the security constraint resolves dot-segments in the 
request path
+
+A `netty-http` consumer configured with a `securityConstraint` now resolves 
`.` and `..` segments in the request path
+(including their percent-encoded `%2e` form) before the path is matched 
against the configured inclusions and exclusions,
+following the `remove_dot_segments` algorithm of RFC 3986. The constraint is 
therefore evaluated against the effective
+resolved path, which is the same resource the request is routed to. Excess 
`..` segments cannot climb above the root.

Review Comment:
   Fixed. The guide entry is rewritten for the new behavior — a request path 
with dot-segments is rejected with 400 when a `securityConstraint` is 
configured — and the "same resource the request is routed to" claim is removed, 
since the route receives the raw path.
   
   _Claude Code on behalf of oscerd_
   



-- 
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