Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanse fileId for logging #105

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 +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);
LOG.debug("File Service: File with ID " + fileId + " was loaded from the repo");
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
Loading