sunrisefromdark commented on code in PR #8963:
URL: https://github.com/apache/inlong/pull/8963#discussion_r1333105032


##########
inlong-tubemq/tubemq-manager/src/main/java/org/apache/inlong/tubemq/manager/utils/HttpUtils.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.inlong.tubemq.manager.utils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.regex.Pattern;
+
+public class HttpUtils {
+
+    private static final Pattern IP_PATTERN = 
Pattern.compile("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$");
+
+    public static String sendHttpGetRequest(String url) throws IOException {
+        // Verify that the host name and port number are legitimate
+        URL requestUrl = new URL(url);
+        String host = requestUrl.getHost();
+        int port = requestUrl.getPort();
+        if (!isValidIpAddress(host)) {
+            throw new SecurityException("Invalid IP address");
+        }
+
+        if (!isValidPort(port)) {
+            throw new SecurityException("Invalid port number");
+        }
+        HttpURLConnection connection = (HttpURLConnection) 
requestUrl.openConnection();

Review Comment:
   I used the Apache HttpClient library instead of using HttpURLConnection 
directly from the Java standard library and added input validation, special 
character filtering, URL format validation, path traversal detection, length 
detection, audit logging, and other features to address the risk of this SSRF 
attack.



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