Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cb 6085 fix regex in web sql file loader servlet #3164

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -89,19 +88,21 @@ protected void processServiceRequest(
Map<String, Object> 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());
}
}
}
Loading