diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLFileLoaderServlet.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLFileLoaderServlet.java index d70a9ab318..cced78d2d7 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLFileLoaderServlet.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLFileLoaderServlet.java @@ -39,6 +39,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; +import java.util.UUID; @MultipartConfig public class WebSQLFileLoaderServlet extends WebServiceServletBase { @@ -53,8 +54,6 @@ public class WebSQLFileLoaderServlet extends WebServiceServletBase { private static final String FILE_ID = "fileId"; - private static final String FORBIDDEN_CHARACTERS_FILE_REGEX = "(?U)[$()@ /]+"; - private static final Gson gson = new GsonBuilder() .serializeNulls() .setPrettyPrinting() @@ -89,19 +88,21 @@ protected void processServiceRequest( Map variables = gson.fromJson(request.getParameter(REQUEST_PARAM_VARIABLES), MAP_STRING_OBJECT_TYPE); String fileId = JSONUtils.getString(variables, FILE_ID); - - if (fileId != null && !fileId.matches(FORBIDDEN_CHARACTERS_FILE_REGEX) && !fileId.startsWith(".")) { - Path file = tempFolder.resolve(fileId); - try { - Files.write(file, request.getPart("fileData").getInputStream().readAllBytes()); - } catch (ServletException e) { - log.error(e.getMessage()); - throw new DBWebException(e.getMessage()); - } - } else { - String illegalCharacters = fileId != null ? - fileId.replaceAll(FORBIDDEN_CHARACTERS_FILE_REGEX, " ").strip() : null; - throw new DBException("Resource path '" + fileId + "' contains illegal characters: " + illegalCharacters); + if (fileId == null) { + throw new DBWebException("File ID not found"); + } + try { + // file id must be UUID + UUID.fromString(fileId); + } catch (IllegalArgumentException e) { + throw new DBWebException("File ID is invalid"); + } + Path file = tempFolder.resolve(fileId); + try { + Files.write(file, request.getPart("fileData").getInputStream().readAllBytes()); + } catch (ServletException e) { + log.error(e.getMessage()); + throw new DBWebException(e.getMessage()); } } } \ No newline at end of file