@@ -126,6 +126,7 @@ public Result<Object> createDirectory(User loginUser, String name, ResourceType
126
126
}
127
127
128
128
String tenantCode = getTenantCode (user );
129
+ checkFullName (tenantCode , currentDir );
129
130
130
131
String userResRootPath = ResourceType .UDF .equals (type ) ? storageOperate .getUdfDir (tenantCode )
131
132
: storageOperate .getResDir (tenantCode );
@@ -171,6 +172,7 @@ public Result<Object> uploadResource(User loginUser, String name, ResourceType t
171
172
}
172
173
173
174
String tenantCode = getTenantCode (user );
175
+ checkFullName (tenantCode , currentDir );
174
176
175
177
result = verifyFile (name , type , file );
176
178
if (!result .getCode ().equals (Status .SUCCESS .getCode ())) {
@@ -257,14 +259,15 @@ public Result<Object> updateResource(User loginUser, String resourceFullName, St
257
259
}
258
260
259
261
String tenantCode = getTenantCode (user );
262
+ checkFullName (tenantCode , resourceFullName );
260
263
261
264
if (!isUserTenantValid (isAdmin (loginUser ), tenantCode , resTenantCode )) {
262
265
log .error ("current user does not have permission" );
263
266
putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
264
267
return result ;
265
268
}
266
269
267
- String defaultPath = storageOperate .getResDir ( tenantCode );
270
+ String defaultPath = storageOperate .getDir ( type , tenantCode );
268
271
269
272
StorageEntity resource ;
270
273
try {
@@ -949,6 +952,7 @@ public Result<Object> createResourceFile(User loginUser, ResourceType type, Stri
949
952
}
950
953
951
954
String tenantCode = getTenantCode (user );
955
+ checkFullName (tenantCode , currentDir );
952
956
953
957
if (FileUtils .directoryTraversal (fileName )) {
954
958
log .warn ("File name verify failed, fileName:{}." , RegexUtils .escapeNRT (fileName ));
@@ -1280,9 +1284,19 @@ private String getTenantCode(User user) {
1280
1284
}
1281
1285
1282
1286
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
+ }
1283
1297
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 );
1286
1300
}
1287
1301
}
1288
1302
}
0 commit comments