forked from molecule-ai/molecule-core
fix(security): CWE-78/CWE-22 — block shell injection in deleteViaEphemeral (#1310)
## Summary Issue #1273: deleteViaEphemeral interpolated filePath directly into rm command, enabling both shell injection (CWE-78) and path traversal (CWE-22) attacks. ## Changes 1. Added validateRelPath(filePath) guard before constructing the rm command. validateRelPath blocks absolute paths and ".." traversal sequences. 2. Changed Cmd from "/configs/"+filePath (string interpolation) to []string{"rm", "-rf", "/configs", filePath} (exec form). This eliminates shell injection entirely — filePath is a plain argument, never interpreted as shell code. ## Security properties - validateRelPath: blocks "../" and absolute paths before they reach Docker - Exec form: filePath cannot inject shell metacharacters even if validation is somehow bypassed - "/configs" as separate arg: rm has exactly two arguments, no room for injected args Closes #1273. Co-authored-by: Molecule AI Infra-Runtime-BE <infra-runtime-be@agents.moleculesai.app>
This commit is contained in:
parent
59e7486ef1
commit
49ab614f2f
@ -142,10 +142,16 @@ func (h *TemplatesHandler) deleteViaEphemeral(ctx context.Context, volumeName, f
|
||||
if h.docker == nil {
|
||||
return fmt.Errorf("docker not available")
|
||||
}
|
||||
// CWE-78/CWE-22: validate before use. Also switches to exec form
|
||||
// ([]string{...}) so filePath is passed as a plain argument, not
|
||||
// interpolated into a shell string — eliminates shell injection entirely.
|
||||
if err := validateRelPath(filePath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := h.docker.ContainerCreate(ctx, &container.Config{
|
||||
Image: "alpine:latest",
|
||||
Cmd: []string{"rm", "-rf", "/configs/" + filePath},
|
||||
Cmd: []string{"rm", "-rf", "/configs", filePath},
|
||||
}, &container.HostConfig{
|
||||
Binds: []string{volumeName + ":/configs"},
|
||||
}, nil, nil, "")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user