Skip to content

Commit

Permalink
CB-5609. Added validate name for renaming s3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisSinelnikov committed Dec 25, 2024
1 parent bd85143 commit 7ec638d
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Web file system implementation
*/
public class WebServiceFS implements DBWServiceFS {

public static final String FORBIDDEN_FILENAME_REGEX = "[%#:;№_$]";

@NotNull
@Override
public FSFileSystem[] getAvailableFileSystems(@NotNull WebSession webSession, @NotNull String projectId)
Expand Down Expand Up @@ -208,6 +212,7 @@ public FSFile renameFile(
@NotNull String nodePath,
@NotNull String newName
) throws DBWebException {
validateFilename(newName);
try {
DBNPathBase node = FSUtils.getNodeByPath(webSession, nodePath);
node.rename(webSession.getProgressMonitor(), newName);
Expand Down Expand Up @@ -276,4 +281,13 @@ public boolean deleteFile(
throw new DBWebException("Failed to create folder: " + e.getMessage(), e);
}
}

private static void validateFilename(String filename) throws DBWebException {
Pattern pattern = Pattern.compile(FORBIDDEN_FILENAME_REGEX);
Matcher matcher = pattern.matcher(filename);

if (matcher.find()) {
throw new DBWebException("File include forbidden symbols: " + filename);
}
}
}

0 comments on commit 7ec638d

Please sign in to comment.