gnodet-bot commented on code in PR #27945:
URL: https://github.com/apache/camel/pull/27945#discussion_r4305961070
##########
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:
⚠️ **Constraint/route path asymmetry not addressed.** `extractTarget` now
checks the resolved path, but `HttpServerMultiplexChannelHandler.getHandler`
dispatches on `request.uri()` (raw) and `DefaultNettyHttpBinding.stripPath`
writes `uri.getRawPath()` into `CamelHttpPath`. The route therefore never sees
the resolved path.
This opens a reverse bypass: with `/admin/*` restricted and `/public/*`
excluded, `/foo/admin/../public/x` now resolves to `/public/x` at
constraint-evaluation time (treated as public), but the route receives
`CamelHttpPath=/admin/../public/x` — a route branching on that value runs admin
logic unauthenticated.
@davsclaus's two options:
- **400-reject** any request whose decoded path differs from its
`removeDotSegments` result when a constraint is active (matches Spring
`StrictHttpFirewall`, simplest).
- **Dual evaluation**: check both raw and resolved targets, challenging if
either matches a restricted inclusion.
##########
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:
⚠️ **Missing test coverage.** All three tests use `/foo/../admin/x`, which
resolves *outside* the `/foo` endpoint context — they pass only because the
absolute `/admin/x` matches the `/admin/*` inclusion by coincidence of the path
stripping.
@davsclaus asked for:
1. In-context traversal: `/foo/x/../admin/y` (both `x` and `admin` are under
`/foo`)
2. Reverse-direction test: `/foo/admin/../public/x` with a `/public/*`
exclusion — this should be *challenged* but the asymmetry now treats it as
public.
##########
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:
⚠️ **Inaccurate wording** (still open from @davsclaus's review): "which is
the same resource the request is routed to" is incorrect — netty-http
dispatches on `request.uri()` (raw) and sets `CamelHttpPath` from
`uri.getRawPath()`. The route never sees the resolved path. This sentence
should be removed or reworded once the architectural approach is settled.
--
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]