moresandeep commented on code in PR #1062: URL: https://github.com/apache/knox/pull/1062#discussion_r2219428603
########## gateway-server/src/main/java/org/apache/knox/gateway/util/ExceptionSanitizer.java: ########## @@ -0,0 +1,36 @@ +/* + * 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.knox.gateway.util; + +import org.apache.knox.gateway.SanitizedException; + +import java.util.Objects; + +public class ExceptionSanitizer { + + private ExceptionSanitizer() { + } + + public static SanitizedException from(final Exception e, final boolean isSanitizationEnabled, final String pattern) { + if (Objects.isNull(e) || Objects.isNull(e.getMessage())) { + return new SanitizedException(); Review Comment: In case there is no offending message (i.e. the message does not contain IP address) shouldn't we just throw the same exception instead of SanitizedException? looks like this might a) hide the original exception b) add new stack trace that won't be useful. ########## gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java: ########## @@ -45,11 +45,17 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.util.Enumeration; +import java.util.Objects; + +import static org.apache.knox.gateway.util.ExceptionSanitizer.from; public class GatewayServlet implements Servlet, Filter { public static final String GATEWAY_DESCRIPTOR_LOCATION_DEFAULT = "gateway.xml"; public static final String GATEWAY_DESCRIPTOR_LOCATION_PARAM = "gatewayDescriptorLocation"; + private static boolean isErrorMessageSanitizationEnabled = true; + private static String errorMessageSanitizationPattern = "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b"; Review Comment: Should we also add support for ipv6? -- 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: dev-unsubscr...@knox.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org