Skip to content

Commit

Permalink
Code Review Update 3rd:
Browse files Browse the repository at this point in the history
- Fixed CodeQL: Uncontrolled data used in path expression
  • Loading branch information
Mighten committed Sep 22, 2024
1 parent abda5a4 commit b4a834e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ public class CosStorageConstants {
public static final String TENCENT_CLOUD_ACCESS_KEY_ID = "resource.tencent.cloud.access.key.id";
public static final String TENCENT_CLOUD_ACCESS_KEY_SECRET = "resource.tencent.cloud.access.key.secret";

public static final String ILLEGAL_DOWNLOAD_PATH_PREFIX_ETC = "/etc";
public static final String DEFAULT_COS_RESOURCE_UPLOAD_PATH = "/dolphinscheduler";
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,14 @@ public void createStorageDir(String directoryAbsolutePath) {
@Override
public void download(String srcFilePath, String dstFilePath, boolean overwrite) {
String cosKey = transformAbsolutePathToCOSKey(srcFilePath);
Path normalizedFilePath = Paths.get(dstFilePath).normalize();
if (normalizedFilePath.startsWith(CosStorageConstants.ILLEGAL_DOWNLOAD_PATH_PREFIX_ETC)) {
throw new IllegalArgumentException("failed to download to " + normalizedFilePath);
Path dsTempFolder = Paths.get(FileUtils.DATA_BASEDIR).normalize().toAbsolutePath();
Path fileDownloadPathNormalized = dsTempFolder.resolve(dstFilePath).normalize().toAbsolutePath();
if (!fileDownloadPathNormalized.startsWith(dsTempFolder)) {
// if the destination file path is NOT in DS temp folder (e.g., '/tmp/dolphinscheduler'),
// an IllegalArgumentException should be thrown.
throw new IllegalArgumentException("failed to download to " + fileDownloadPathNormalized);
}
File dstFile = normalizedFilePath.toFile();
File dstFile = fileDownloadPathNormalized.toFile();
if (dstFile.isDirectory()) {
Files.delete(dstFile.toPath());
} else {
Expand Down

0 comments on commit b4a834e

Please sign in to comment.