Commit 49ab94d0 authored by Junling Bu's avatar Junling Bu
Browse files

fix[litemall-wx-api]: 修复文件路径中包含"../"带来的安全问题

parent 3313051c
...@@ -58,14 +58,17 @@ public class WxStorageController { ...@@ -58,14 +58,17 @@ public class WxStorageController {
public ResponseEntity<Resource> fetch(@PathVariable String key) { public ResponseEntity<Resource> fetch(@PathVariable String key) {
LitemallStorage litemallStorage = litemallStorageService.findByKey(key); LitemallStorage litemallStorage = litemallStorageService.findByKey(key);
if (key == null) { if (key == null) {
ResponseEntity.notFound(); return ResponseEntity.notFound().build();
}
if(key.contains("../")){
return ResponseEntity.badRequest().build();
} }
String type = litemallStorage.getType(); String type = litemallStorage.getType();
MediaType mediaType = MediaType.parseMediaType(type); MediaType mediaType = MediaType.parseMediaType(type);
Resource file = storageService.loadAsResource(key); Resource file = storageService.loadAsResource(key);
if (file == null) { if (file == null) {
ResponseEntity.notFound(); return ResponseEntity.notFound().build();
} }
return ResponseEntity.ok().contentType(mediaType).body(file); return ResponseEntity.ok().contentType(mediaType).body(file);
} }
...@@ -74,14 +77,18 @@ public class WxStorageController { ...@@ -74,14 +77,18 @@ public class WxStorageController {
public ResponseEntity<Resource> download(@PathVariable String key) { public ResponseEntity<Resource> download(@PathVariable String key) {
LitemallStorage litemallStorage = litemallStorageService.findByKey(key); LitemallStorage litemallStorage = litemallStorageService.findByKey(key);
if (key == null) { if (key == null) {
ResponseEntity.notFound(); return ResponseEntity.notFound().build();
}
if(key.contains("../")){
return ResponseEntity.badRequest().build();
} }
String type = litemallStorage.getType(); String type = litemallStorage.getType();
MediaType mediaType = MediaType.parseMediaType(type); MediaType mediaType = MediaType.parseMediaType(type);
Resource file = storageService.loadAsResource(key); Resource file = storageService.loadAsResource(key);
if (file == null) { if (file == null) {
ResponseEntity.notFound(); return ResponseEntity.notFound().build();
} }
return ResponseEntity.ok().contentType(mediaType).header(HttpHeaders.CONTENT_DISPOSITION, return ResponseEntity.ok().contentType(mediaType).header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"" + file.getFilename() + "\"").body(file); "attachment; filename=\"" + file.getFilename() + "\"").body(file);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment