Skip to content

Commit

Permalink
Cleanse API input params
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Dec 18, 2024
1 parent 69fced2 commit d05660f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ public ResponseEntity<?> fileUpload(@RequestParam("file") MultipartFile file, Pr
@ResponseBody
public ResponseEntity<?> getFileById(@PathVariable("uuid") String uuid,
@PathVariable("origFileName") String origFileName) {
String fileId = uuid + "/" + origFileName;
if (StringUtils.isEmpty(uuid) || StringUtils.isEmpty(origFileName)) {
LOG.error("File ID not provided to get a file.");
return ResponseEntity.badRequest().body("File ID not provided to get a file.");
}
String cleansedUuid = StringUtils.normalizeSpace(uuid);
String cleansedOrigFileName = StringUtils.normalizeSpace(origFileName);
String fileId = cleansedUuid + "/" + cleansedOrigFileName;

ByteArrayResource fileResource;
String contentType = "";

Expand Down Expand Up @@ -141,7 +144,9 @@ public ResponseEntity<?> deleteFileById(@PathVariable("uuid") String uuid,
@PathVariable("origFileName") String origFileName,
Principal principal, HttpServletRequest request) {
String principalName = principal.getName();
String fileId = uuid + "/" + origFileName;
String cleansedUuid = StringUtils.normalizeSpace(uuid);
String cleansedOrigFileName = StringUtils.normalizeSpace(origFileName);
String fileId = cleansedUuid + "/" + cleansedOrigFileName;

//Get the file, check that it exists, and then check if current user has permissions to delete
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ public ByteArrayResource getFile(String fileId) throws IOException {
}
// the output path for getObject must not exist, hence temp dir is created on the fly
ocflRepository.getObject(ObjectVersionId.head(fileId), tempLoadDir);
if (LOG.isDebugEnabled()) {
LOG.debug("File Service: File with ID {} was loaded from the repo", StringUtils.normalizeSpace(fileId));
}
LOG.debug("File Service: File with ID {} was loaded from the repo", fileId);
Path fileNamePath = Objects.requireNonNull(tempLoadDir.toFile().listFiles())[0].toPath();
loadedResource = new ByteArrayResource(Files.readAllBytes(fileNamePath));

Expand Down

0 comments on commit d05660f

Please sign in to comment.