Skip to content

Commit 75707cb

Browse files
authored
Merge branch 'dev' into dev
2 parents d00c31f + 8acc697 commit 75707cb

File tree

4 files changed

+168
-193
lines changed

4 files changed

+168
-193
lines changed

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java

+2
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ public enum Status {
323323

324324
REMOVE_TASK_INSTANCE_CACHE_ERROR(20019, "remove task instance cache error", "删除任务实例缓存错误"),
325325

326+
ILLEGAL_RESOURCE_PATH(20020, "Resource file [{0}] is illegal", "非法的资源路径[{0}]"),
327+
326328
USER_NO_OPERATION_PERM(30001, "user has no operation privilege", "当前用户没有操作权限"),
327329
USER_NO_OPERATION_PROJECT_PERM(30002, "user {0} is not has project {1} permission", "当前用户[{0}]没有[{1}]项目的操作权限"),
328330
USER_NO_WRITE_PROJECT_PERM(30003, "user [{0}] does not have write permission for project [{1}]",

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ Result<Object> updateResourceContent(User loginUser, String fullName, String ten
194194
org.springframework.core.io.Resource downloadResource(User loginUser, String fullName) throws IOException;
195195

196196
/**
197-
* Get resource by given resource type and full name.
197+
* Get resource by given resource type and file name.
198198
* Useful in Python API create task which need processDefinition information.
199199
*
200200
* @param userName user who query resource
201-
* @param fullName full name of the resource
201+
* @param fileName file name of the resource
202202
*/
203-
StorageEntity queryFileStatus(String userName, String fullName) throws Exception;
203+
StorageEntity queryFileStatus(String userName, String fileName) throws Exception;
204204

205205
/**
206206
* delete DATA_TRANSFER data in resource center

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public Result<Object> createDirectory(User loginUser, String name, ResourceType
126126
}
127127

128128
String tenantCode = getTenantCode(user);
129+
checkFullName(tenantCode, currentDir);
129130

130131
String userResRootPath = ResourceType.UDF.equals(type) ? storageOperate.getUdfDir(tenantCode)
131132
: storageOperate.getResDir(tenantCode);
@@ -171,6 +172,7 @@ public Result<Object> uploadResource(User loginUser, String name, ResourceType t
171172
}
172173

173174
String tenantCode = getTenantCode(user);
175+
checkFullName(tenantCode, currentDir);
174176

175177
result = verifyFile(name, type, file);
176178
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
@@ -257,14 +259,15 @@ public Result<Object> updateResource(User loginUser, String resourceFullName, St
257259
}
258260

259261
String tenantCode = getTenantCode(user);
262+
checkFullName(tenantCode, resourceFullName);
260263

261264
if (!isUserTenantValid(isAdmin(loginUser), tenantCode, resTenantCode)) {
262265
log.error("current user does not have permission");
263266
putMsg(result, Status.NO_CURRENT_OPERATING_PERMISSION);
264267
return result;
265268
}
266269

267-
String defaultPath = storageOperate.getResDir(tenantCode);
270+
String defaultPath = storageOperate.getDir(type, tenantCode);
268271

269272
StorageEntity resource;
270273
try {
@@ -949,6 +952,7 @@ public Result<Object> createResourceFile(User loginUser, ResourceType type, Stri
949952
}
950953

951954
String tenantCode = getTenantCode(user);
955+
checkFullName(tenantCode, currentDir);
952956

953957
if (FileUtils.directoryTraversal(fileName)) {
954958
log.warn("File name verify failed, fileName:{}.", RegexUtils.escapeNRT(fileName));
@@ -1280,9 +1284,19 @@ private String getTenantCode(User user) {
12801284
}
12811285

12821286
private void checkFullName(String userTenantCode, String fullName) {
1287+
if (StringUtils.isEmpty(fullName)) {
1288+
return;
1289+
}
1290+
if (FOLDER_SEPARATOR.equalsIgnoreCase(fullName)) {
1291+
return;
1292+
}
1293+
// Avoid returning to the parent directory
1294+
if (fullName.contains("../")) {
1295+
throw new ServiceException(Status.ILLEGAL_RESOURCE_PATH, fullName);
1296+
}
12831297
String baseDir = storageOperate.getDir(ResourceType.ALL, userTenantCode);
1284-
if (StringUtils.isNotBlank(fullName) && !StringUtils.startsWith(fullName, baseDir)) {
1285-
throw new ServiceException("Resource file: " + fullName + " is illegal");
1298+
if (!StringUtils.startsWith(fullName, baseDir)) {
1299+
throw new ServiceException(Status.ILLEGAL_RESOURCE_PATH, fullName);
12861300
}
12871301
}
12881302
}

0 commit comments

Comments
 (0)