Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

FIX (system/agent): resolve binary path via constant map to clear CodeQL "uncontrolled data in path expression" findings

Rostislav Duginf17d1308c841
diff --git a/backend/internal/features/system/agent/controller.go b/backend/internal/features/system/agent/controller.go
index a680dac5..a5a8f30e 100644
--- a/backend/internal/features/system/agent/controller.go
+++ b/backend/internal/features/system/agent/controller.go
@@ -3,7 +3,6 @@ package system_agent
import (
"net/http"
"os"
- "path/filepath"
"github.com/gin-gonic/gin"
)
@@ -15,6 +14,16 @@ func (c *AgentController) RegisterRoutes(router *gin.RouterGroup) {
router.GET("/system/verification-agent", c.DownloadVerificationAgent)
}
+var agentBinaryPaths = map[string]string{
+ "amd64": "agent-binaries/databasus-agent-linux-amd64",
+ "arm64": "agent-binaries/databasus-agent-linux-arm64",
+}
+
+var verificationAgentBinaryPaths = map[string]string{
+ "amd64": "agent-binaries/databasus-verification-agent-linux-amd64",
+ "arm64": "agent-binaries/databasus-verification-agent-linux-arm64",
+}
+
// DownloadAgent
// @Summary Download agent binary
// @Description Download the databasus-agent binary for the specified architecture
@@ -26,20 +35,14 @@ func (c *AgentController) RegisterRoutes(router *gin.RouterGroup) {
// @Failure 404 {object} map[string]string
// @Router /system/agent [get]
func (c *AgentController) DownloadAgent(ctx *gin.Context) {
- arch := ctx.Query("arch")
- if arch != "amd64" && arch != "arm64" {
+ binaryPath, isOk := agentBinaryPaths[ctx.Query("arch")]
+ if !isOk {
ctx.JSON(http.StatusBadRequest, gin.H{"error": "arch must be amd64 or arm64"})
return
}
- binaryName := "databasus-agent-linux-" + arch
- binaryPath := filepath.Join("agent-binaries", binaryName)
-
if _, err := os.Stat(binaryPath); os.IsNotExist(err) {
- ctx.JSON(
- http.StatusNotFound,
- gin.H{"error": "agent binary not found for architecture: " + arch},
- )
+ ctx.JSON(http.StatusNotFound, gin.H{"error": "agent binary not found"})
return
}
@@ -59,20 +62,14 @@ func (c *AgentController) DownloadAgent(ctx *gin.Context) {
// @Failure 404 {object} map[string]string
// @Router /system/verification-agent [get]
func (c *AgentController) DownloadVerificationAgent(ctx *gin.Context) {
- arch := ctx.Query("arch")
- if arch != "amd64" && arch != "arm64" {
+ binaryPath, isOk := verificationAgentBinaryPaths[ctx.Query("arch")]
+ if !isOk {
ctx.JSON(http.StatusBadRequest, gin.H{"error": "arch must be amd64 or arm64"})
return
}
- binaryName := "databasus-verification-agent-linux-" + arch
- binaryPath := filepath.Join("agent-binaries", binaryName)
-
if _, err := os.Stat(binaryPath); os.IsNotExist(err) {
- ctx.JSON(
- http.StatusNotFound,
- gin.H{"error": "verification agent binary not found for architecture: " + arch},
- )
+ ctx.JSON(http.StatusNotFound, gin.H{"error": "verification agent binary not found"})
return
}