Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fix issue #842 - A security vulnerability relating to path traversal
  • Loading branch information
robinshine committed Aug 9, 2022
1 parent 6ecf335 commit 5b6a19c
Showing 1 changed file with 25 additions and 20 deletions.
Expand Up @@ -78,30 +78,35 @@ public void onClick(AjaxRequestTarget target) {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
super.onSubmit(target, form);

LockUtils.write(getBuild().getArtifactsLockKey(), new Callable<Void>() {
if (directory.contains("..")) {
error("'..' is not allowed in the directory");
target.add(feedback);
} else {
LockUtils.write(getBuild().getArtifactsLockKey(), new Callable<Void>() {

@Override
public Void call() throws Exception {
File artifactsDir = getBuild().getArtifactsDir();
for (FileUpload upload: uploads) {
String filePath = FilenameUtils.sanitizeFilename(upload.getFileName());
if (directory != null)
filePath = directory + "/" + filePath;
File file = new File(artifactsDir, filePath);
FileUtils.createDir(file.getParentFile());
try ( InputStream is = upload.getInputStream();
OutputStream os = new FileOutputStream(file)) {
IOUtils.copy(is, os);
} finally {
upload.release();
@Override
public Void call() throws Exception {
File artifactsDir = getBuild().getArtifactsDir();
for (FileUpload upload: uploads) {
String filePath = FilenameUtils.sanitizeFilename(upload.getFileName());
if (directory != null)
filePath = directory + "/" + filePath;
File file = new File(artifactsDir, filePath);
FileUtils.createDir(file.getParentFile());
try ( InputStream is = upload.getInputStream();
OutputStream os = new FileOutputStream(file)) {
IOUtils.copy(is, os);
} finally {
upload.release();
}
}
return null;
}
return null;
}

});

});

onUploaded(target);
onUploaded(target);
}
}

@Override
Expand Down

0 comments on commit 5b6a19c

Please sign in to comment.