Skip to content

Commit

Permalink
fix the symlink and bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ZihengSun committed Sep 16, 2024
1 parent 58cdb2e commit 783d2f8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>com.gw</groupId>
<artifactId>geoweaver</artifactId>
<version>1.7.1</version>
<version>1.7.3</version>
<name>geoweaver</name>
<description>A lightweight workflow management software for organizing data analysis workflows,
preserving history of every workflow run, and improving scientist producitvity and workflow FAIRness,
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/com/gw/web/ResultBrowserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -33,6 +34,9 @@ public class ResultBrowserController {

@Autowired BaseTool bt;

@Value("${geoweaver.follow_symlinks:false}")
boolean follow_symlinks;

// Inject the directory path from application.properties

// Endpoint to list image files in the directory
Expand All @@ -43,20 +47,32 @@ public List<Map<String, Object>> listFiles(@RequestParam(defaultValue = "") Stri

// Navigate into the subfolder if it's provided
Path rootLocation = Paths.get(resultfolder, subfolder);
System.out.println("Received " + subfolder);

Stream<Path> walker = null;

if(follow_symlinks){
// 1: look at files in the current folder and subfolders
walker = Files.walk(rootLocation, 1, FileVisitOption.FOLLOW_LINKS);
}else{
walker = Files.walk(rootLocation, 1);
}

return Files.walk(rootLocation, 1) // 1: look at files in the current folder and subfolders
.map(path -> {
return walker.map(path -> {
Map<String, Object> fileDetails = new HashMap<>();
try {
System.out.println(path);
Path relativePath = rootLocation.relativize(path);
String pathWithSubfolder = subfolder + "/" + relativePath.toString();
pathWithSubfolder = pathWithSubfolder.replaceAll("^/+","");

// Check if pathWithSubfolder contains any attempts to go up the directory
Path normalizedSubfolderPath = Paths.get(pathWithSubfolder).normalize();
System.out.println("normalizedSubfolderPath = " + normalizedSubfolderPath);
if (normalizedSubfolderPath.startsWith("..")) {
throw new SecurityException("Attempt to access outside of the result folder is not allowed.");
}
System.out.println("pathWithSubfolder = " + pathWithSubfolder);

fileDetails.put("name", rootLocation.relativize(path).toString()); // Relative path
fileDetails.put("path", pathWithSubfolder); // Relative path
Expand All @@ -79,7 +95,7 @@ public List<Map<String, Object>> listFiles(@RequestParam(defaultValue = "") Stri
fileDetails.put("modified", formattedDateTime);
} catch (IOException e){
e.printStackTrace();
}catch (SecurityException e) {
} catch (SecurityException e) {
System.out.println("Error: " + (e.getMessage() != null ? e.getMessage() : "Unknown error occurred"));
throw e;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@ geoweaver.allowed_ssh_hosts=*
# list the allowed ssh clients. Input * if allowing all client IPs. Input localhost if only allowing access from local host.
geoweaver.allowed_ssh_clients=*
geoweaver.secret_properties_path=cc_secret.properties
geoweaver.follow_symlinks=true


2 changes: 1 addition & 1 deletion src/main/resources/static/js/gw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edu = {
sponsor:
"ESIPLab incubator project, NASA ACCESS project, NSF Geoinformatics project, NSF Cybertraining project",

version: "1.7.2",
version: "1.7.3",

author: "open source contributors",

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ geoweaver.upload_file_path=temp
geoweaver.temp_file_path=temp
geoweaver.workspace=~/gw-workspace
geoweaver.result_file_path=results
geoweaver.follow_symlinks=true

# list the allowed ssh hosts. Input * if allowing all hosts. Input localhost if only allowing the local host.
geoweaver.allowed_ssh_hosts=*
Expand Down

0 comments on commit 783d2f8

Please sign in to comment.