github-advanced-security[bot] commented on code in PR #7940:
URL: https://github.com/apache/geode/pull/7940#discussion_r2432823497
##########
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java:
##########
@@ -251,4 +294,48 @@
return result;
}
}
+
+ /**
+ * Security: Validates JAR file paths to prevent path injection attacks.
+ *
+ * This method addresses CodeQL vulnerability java/path-injection by ensuring
+ * that user-provided file paths are safe to access and don't contain
malicious
+ * path traversal sequences.
+ *
+ * @param jarPath The JAR file path to validate
+ * @throws IllegalArgumentException if the path is invalid or unsafe
+ */
+ private void validateJarPath(String jarPath) {
+ if (jarPath == null || jarPath.trim().isEmpty()) {
+ throw new IllegalArgumentException("JAR file path cannot be null or
empty");
+ }
+
+ // Security: Prevent path traversal attacks
+ if (jarPath.contains("..") || jarPath.contains("~")) {
+ throw new IllegalArgumentException("Invalid JAR file path: path
traversal detected");
+ }
+
+ File jarFile = new File(jarPath);
+
+ // Security: Ensure the file exists and is a regular file
+ if (!jarFile.exists()) {
+ throw new IllegalArgumentException("JAR file does not exist: " +
jarFile.getName());
+ }
+
+ if (!jarFile.isFile()) {
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
This path depends on a [user-provided value](2).
[Show more
details](https://github.com/apache/geode/security/code-scanning/125)
##########
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java:
##########
@@ -251,4 +294,48 @@
return result;
}
}
+
+ /**
+ * Security: Validates JAR file paths to prevent path injection attacks.
+ *
+ * This method addresses CodeQL vulnerability java/path-injection by ensuring
+ * that user-provided file paths are safe to access and don't contain
malicious
+ * path traversal sequences.
+ *
+ * @param jarPath The JAR file path to validate
+ * @throws IllegalArgumentException if the path is invalid or unsafe
+ */
+ private void validateJarPath(String jarPath) {
+ if (jarPath == null || jarPath.trim().isEmpty()) {
+ throw new IllegalArgumentException("JAR file path cannot be null or
empty");
+ }
+
+ // Security: Prevent path traversal attacks
+ if (jarPath.contains("..") || jarPath.contains("~")) {
+ throw new IllegalArgumentException("Invalid JAR file path: path
traversal detected");
+ }
+
+ File jarFile = new File(jarPath);
+
+ // Security: Ensure the file exists and is a regular file
+ if (!jarFile.exists()) {
+ throw new IllegalArgumentException("JAR file does not exist: " +
jarFile.getName());
+ }
+
+ if (!jarFile.isFile()) {
+ throw new IllegalArgumentException(
+ "Path does not point to a regular file: " + jarFile.getName());
+ }
+
+ // Security: Validate file extension (basic check for JAR files)
+ String fileName = jarFile.getName().toLowerCase();
+ if (!fileName.endsWith(".jar")) {
+ throw new IllegalArgumentException("File is not a JAR file: " +
jarFile.getName());
+ }
+
+ // Security: Ensure the file is readable
+ if (!jarFile.canRead()) {
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
This path depends on a [user-provided value](2).
[Show more
details](https://github.com/apache/geode/security/code-scanning/126)
##########
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java:
##########
@@ -251,4 +294,48 @@
return result;
}
}
+
+ /**
+ * Security: Validates JAR file paths to prevent path injection attacks.
+ *
+ * This method addresses CodeQL vulnerability java/path-injection by ensuring
+ * that user-provided file paths are safe to access and don't contain
malicious
+ * path traversal sequences.
+ *
+ * @param jarPath The JAR file path to validate
+ * @throws IllegalArgumentException if the path is invalid or unsafe
+ */
+ private void validateJarPath(String jarPath) {
+ if (jarPath == null || jarPath.trim().isEmpty()) {
+ throw new IllegalArgumentException("JAR file path cannot be null or
empty");
+ }
+
+ // Security: Prevent path traversal attacks
+ if (jarPath.contains("..") || jarPath.contains("~")) {
+ throw new IllegalArgumentException("Invalid JAR file path: path
traversal detected");
+ }
+
+ File jarFile = new File(jarPath);
+
+ // Security: Ensure the file exists and is a regular file
+ if (!jarFile.exists()) {
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
This path depends on a [user-provided value](2).
[Show more
details](https://github.com/apache/geode/security/code-scanning/124)
##########
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/ImportClusterConfigurationCommand.java:
##########
@@ -175,7 +214,27 @@
File getUploadedFile() {
List<String> filePathFromShell =
CommandExecutionContext.getFilePathFromShell();
- return new File(filePathFromShell.get(0));
+ String filePath = filePathFromShell.get(0);
+
+ // Security: Validate file path to prevent path injection attacks
+ // Ensure the file path doesn't contain directory traversal attempts
+ if (filePath.contains("..") || filePath.contains("~")) {
+ throw new IllegalArgumentException(
+ "Invalid file path: path traversal detected in " + filePath);
+ }
+
+ File file = new File(filePath);
+
+ // Security: Ensure the file exists and is a regular file (not a directory
or special file)
+ if (!file.exists()) {
+ throw new IllegalArgumentException("File does not exist: " +
file.getName());
+ }
+ if (!file.isFile()) {
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
This path depends on a [user-provided value](2).
[Show more
details](https://github.com/apache/geode/security/code-scanning/128)
##########
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/ImportClusterConfigurationCommand.java:
##########
@@ -175,7 +214,27 @@
File getUploadedFile() {
List<String> filePathFromShell =
CommandExecutionContext.getFilePathFromShell();
- return new File(filePathFromShell.get(0));
+ String filePath = filePathFromShell.get(0);
+
+ // Security: Validate file path to prevent path injection attacks
+ // Ensure the file path doesn't contain directory traversal attempts
+ if (filePath.contains("..") || filePath.contains("~")) {
+ throw new IllegalArgumentException(
+ "Invalid file path: path traversal detected in " + filePath);
+ }
+
+ File file = new File(filePath);
+
+ // Security: Ensure the file exists and is a regular file (not a directory
or special file)
+ if (!file.exists()) {
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
This path depends on a [user-provided value](2).
[Show more
details](https://github.com/apache/geode/security/code-scanning/127)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]