Skip to content

Conversation

@jdrodjpl
Copy link
Collaborator

@jdrodjpl jdrodjpl commented Jan 9, 2025

…f un/installation.

Files are:

pre-install.sh
post-install.sh
pre-uninstall.sh
post-uninstall.sh

If these files are found in the base dir of the marketplace item they will be executed either before or after the terraform is executed.

The scripts will be executed in the base dir of the marketplace item and should have access to the main terraform environment.

logfile := filepath.Join(logDir, fmt.Sprintf("%s_%s_install_log", application.Name, application.DeploymentName))

// Open the log file in append mode
fileHandle, err := os.OpenFile(logfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Copilot Autofix

AI 11 months ago

To fix the problem, we need to validate the user input before using it to construct the file path. Specifically, we should ensure that the application.Name and application.DeploymentName fields do not contain any path separators or parent directory references. This can be done by checking for the existence of any path separators ("/" or "\") or ".." sequences in the input, and rejecting the input if any are found.

Suggested changeset 1
backend/internal/processes/installer.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/backend/internal/processes/installer.go b/backend/internal/processes/installer.go
--- a/backend/internal/processes/installer.go
+++ b/backend/internal/processes/installer.go
@@ -88,2 +88,10 @@
 func executeTerraformInstall(db database.Datastore, appConfig *config.AppConfig, meta *marketplace.MarketplaceMetadata, application *types.InstalledMarketplaceApplication, location string) error {
+	// Validate application.Name and application.DeploymentName
+	if strings.Contains(application.Name, "/") || strings.Contains(application.Name, "\\") || strings.Contains(application.Name, "..") {
+		return fmt.Errorf("invalid application name: %s", application.Name)
+	}
+	if strings.Contains(application.DeploymentName, "/") || strings.Contains(application.DeploymentName, "\\") || strings.Contains(application.DeploymentName, "..") {
+		return fmt.Errorf("invalid deployment name: %s", application.DeploymentName)
+	}
+
 	// Create install_logs directory if it doesn't exist
EOF
@@ -88,2 +88,10 @@
func executeTerraformInstall(db database.Datastore, appConfig *config.AppConfig, meta *marketplace.MarketplaceMetadata, application *types.InstalledMarketplaceApplication, location string) error {
// Validate application.Name and application.DeploymentName
if strings.Contains(application.Name, "/") || strings.Contains(application.Name, "\\") || strings.Contains(application.Name, "..") {
return fmt.Errorf("invalid application name: %s", application.Name)
}
if strings.Contains(application.DeploymentName, "/") || strings.Contains(application.DeploymentName, "\\") || strings.Contains(application.DeploymentName, "..") {
return fmt.Errorf("invalid deployment name: %s", application.DeploymentName)
}

// Create install_logs directory if it doesn't exist
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants