Skip to content
Open
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 @@ -159,7 +159,7 @@ public ContainerModel createContainer(Sandbox sandbox) throws JsonProcessingExce
logger.info("Docker image is ready: {}", imageName);
}

String sessionId = RandomStringGenerator.generateRandomString(22);
String sessionId = sandbox.getSessionId();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

The sessionId obtained here is used on line 164 to construct a directory path. As the PR description indicates, the sessionId can come from a user-controlled source like a URL path parameter. This creates a critical path traversal vulnerability. A malicious user could provide a sessionId like ../../sensitive-data to create directories and potentially mount host paths outside of the intended sessions_mount_dir.

To mitigate this, you must validate the sessionId to prevent path traversal. Here is a robust way to do it using java.nio.file.Path:

// After getting the sessionId
Path mountPath = Paths.get(currentDir, default_mount_dir, sessionId).toAbsolutePath().normalize();
Path basePath = Paths.get(currentDir, default_mount_dir).toAbsolutePath().normalize();

if (!mountPath.startsWith(basePath)) {
    throw new IllegalArgumentException("Invalid sessionId, potential path traversal attempt.");
}

String mountDir = mountPath.toString();
// ... then use mountDir

This ensures that the resolved path for the session's mount directory is always inside the expected base directory.

String currentDir = System.getProperty("user.dir");
String mountDir = currentDir + "/" + default_mount_dir + "/" + sessionId;

Expand Down
Loading