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-5609. Added validate name for renaming s3 files #3163

Merged
merged 6 commits into from
Dec 27, 2024
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 @@ -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 {

private static final Pattern FORBIDDEN_FILENAME_PATTERN = Pattern.compile("[%#:;№$]");

@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,12 @@ public boolean deleteFile(
throw new DBWebException("Failed to create folder: " + e.getMessage(), e);
}
}

private void validateFilename(@NotNull String filename) throws DBWebException {
Matcher matcher = FORBIDDEN_FILENAME_PATTERN.matcher(filename);

if (matcher.find()) {
throw new DBWebException(String.format("File %s contains forbidden symbols", filename));
}
}
}
Loading