davsclaus commented on code in PR #27718: URL: https://github.com/apache/camel/pull/27718#discussion_r4251269890
########## components/camel-oauth/src/main/java/org/apache/camel/oauth/ServletHttpRequestHeaders.java: ########## @@ -0,0 +1,59 @@ +/* + * 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.oauth; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import jakarta.servlet.http.HttpServletRequest; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.http.common.HttpMessage; + +/** + * Reads request headers from a message of the servlet based HTTP consumers. Only loaded for a message of such a type, + * see {@link HttpRequestHeaders}. + */ +final class ServletHttpRequestHeaders { + + private ServletHttpRequestHeaders() { + } + + /** + * Reads the headers of the request of a camel-http-common {@link HttpMessage} (camel-servlet, camel-jetty). + */ + static Optional<List<String>> values(Message message, String name) { + return values(((HttpMessage) message).getRequest(), name); + } + + /** + * Reads the headers of the request that the message holds in the {@link Exchange#HTTP_SERVLET_REQUEST} header, as + * the message of platform-http on Spring Boot does. + */ + static Optional<List<String>> valuesOfServletRequestHeader(Message message, String name) { + return message.getHeader(Exchange.HTTP_SERVLET_REQUEST) instanceof HttpServletRequest request + ? values(request, name) : Optional.empty(); + } Review Comment: Spring Boot is the only match that finds the request through a message header rather than through the message. If the route removes `CamelHttpServletRequest` before the processor (for example `removeHeaders("Camel*")`, as the security model's hardening checklist recommends for untrusted callers), this returns `Optional.empty()` and `HttpRequestHeaders` falls back to the message headers. There, a urlencoded form field `Authorization=Bearer ...` or `Cookie=...` is read again, because the fallback only filters values that are also in the query string. The real `PlatformHttpMessage` has a public `getRequest()`, which is not affected by removing headers. Some options: - read `getRequest()` reflectively when the header is missing (the class is already matched by name), or - fail closed for this message type: return `Optional.of(List.of())` when no request can be found, so the processor answers 401 rather than reading the message headers. Either way, `springBootMessageWithoutTheServletRequestFallsBackToTheMessageHeaders` would need to change, and the stand-in would need a `getRequest()` for the first option. -- 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]
