github-advanced-security[bot] commented on code in PR #3037:
URL: https://github.com/apache/drill/pull/3037#discussion_r2775024486


##########
exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/SqlLabSpaServlet.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.drill.exec.server.rest;
+
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+
+/**
+ * Servlet for serving the SQL Lab React SPA.
+ * Handles client-side routing by serving index.html for all non-static routes.
+ */
+public class SqlLabSpaServlet extends HttpServlet {
+  private static final Logger logger = 
LoggerFactory.getLogger(SqlLabSpaServlet.class);
+  private static final String WEBAPP_PATH = "/webapp/";
+  private static final String INDEX_HTML = "index.html";
+
+  @Override
+  protected void doGet(HttpServletRequest request, HttpServletResponse 
response)
+      throws ServletException, IOException {
+    String path = request.getPathInfo();
+    if (path == null || path.equals("/")) {
+      path = "/" + INDEX_HTML;
+    }
+
+    // Check if this is a static asset request (has file extension)
+    boolean isStaticAsset = path.lastIndexOf('.') > path.lastIndexOf('/');
+
+    String resourcePath = WEBAPP_PATH + (isStaticAsset ? "dist" + path : 
"dist/" + INDEX_HTML);
+
+    // Try to serve from built assets first
+    URL resource = getClass().getResource(resourcePath);

Review Comment:
   ## Uncontrolled data used in path expression
   
   This path depends on a [user-provided value](1).
   
   [Show more 
details](https://github.com/apache/drill/security/code-scanning/53)



##########
exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/SqlLabSpaServlet.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.drill.exec.server.rest;
+
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+
+/**
+ * Servlet for serving the SQL Lab React SPA.
+ * Handles client-side routing by serving index.html for all non-static routes.
+ */
+public class SqlLabSpaServlet extends HttpServlet {
+  private static final Logger logger = 
LoggerFactory.getLogger(SqlLabSpaServlet.class);
+  private static final String WEBAPP_PATH = "/webapp/";
+  private static final String INDEX_HTML = "index.html";
+
+  @Override
+  protected void doGet(HttpServletRequest request, HttpServletResponse 
response)
+      throws ServletException, IOException {
+    String path = request.getPathInfo();
+    if (path == null || path.equals("/")) {
+      path = "/" + INDEX_HTML;
+    }
+
+    // Check if this is a static asset request (has file extension)
+    boolean isStaticAsset = path.lastIndexOf('.') > path.lastIndexOf('/');
+
+    String resourcePath = WEBAPP_PATH + (isStaticAsset ? "dist" + path : 
"dist/" + INDEX_HTML);
+
+    // Try to serve from built assets first
+    URL resource = getClass().getResource(resourcePath);
+
+    // Fallback to development mode (source files)
+    if (resource == null && isStaticAsset) {
+      resourcePath = WEBAPP_PATH + path.substring(1); // Remove leading slash
+      resource = getClass().getResource(resourcePath);

Review Comment:
   ## Uncontrolled data used in path expression
   
   This path depends on a [user-provided value](1).
   
   [Show more 
details](https://github.com/apache/drill/security/code-scanning/54)



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