File tree Expand file tree Collapse file tree
base/src/main/java/com/tinyengine/it/controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030import jakarta .servlet .http .HttpServletResponse ;
3131import jakarta .validation .Valid ;
3232import org .springframework .beans .factory .annotation .Autowired ;
33+ import org .springframework .util .StringUtils ;
3334import org .springframework .validation .annotation .Validated ;
3435import org .springframework .web .bind .annotation .DeleteMapping ;
3536import org .springframework .web .bind .annotation .GetMapping ;
@@ -188,13 +189,14 @@ public Result<Resource> createResource(@Valid @RequestBody Resource resource) th
188189 @ PostMapping ("/resource/upload" )
189190 public Result <Resource > resourceUpload (@ RequestParam MultipartFile file ) throws Exception {
190191 // 获取文件的原始名称
191- String fileName = file .getOriginalFilename ();
192- if (file .isEmpty ()) {
193- return Result .failed (ExceptionEnum .CM009 );
194- }
192+ String fileName = StringUtils .cleanPath (java .util .Optional .ofNullable (file .getOriginalFilename ()).orElse ("image" ));
193+
195194 if (!ImageThumbnailGenerator .validateByImageIO (file )){
196195 return Result .failed (ExceptionEnum .CM325 );
197196 }
197+ if (fileName .contains (".." )) {
198+ return Result .failed (ExceptionEnum .CM325 );
199+ }
198200 // 将文件转为 Base64
199201 String base64 = ImageThumbnailGenerator .convertToBase64 (file );
200202 Resource resource = new Resource ();
You can’t perform that action at this time.
0 commit comments