fix(F1085): scope rm to /configs volume in deleteViaEphemeral (#1616)

* fix(F1085): scope rm to /configs volume in deleteViaEphemeral

Regressed by commit 49ab614 ("CWE-78/CWE-22 — block shell injection
in deleteViaEphemeral") which changed the rm form from the scoped
concat "/configs/" + filePath to the unscoped 2-arg "/configs", filePath.

With 2 args, rm receives /configs as the first target — rm -rf /configs
attempts to delete the entire volume mount before processing filePath,
which is the F1085 (Misconfiguration - Filesystems) defect. The concat
form passes a single scoped path so rm only touches files inside /configs.

validateRelPath call retained as CWE-22 defence-in-depth.

* docs: note F1085 defect in deleteViaEphemeral 2-arg rm form

Amends the CWE-22+CWE-78 incident entry to record that commit 49ab614
regressed the F1085 (volume deletion scope) fix, and that f1085-fix
commit a432df5 restores the correct concat form.

---------

Co-authored-by: Molecule AI CP-QA <cp-qa@agents.moleculesai.app>
This commit is contained in:
molecule-ai[bot] 2026-04-22 18:44:52 +00:00 committed by GitHub
parent ea5e018f76
commit de11188cc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -224,6 +224,8 @@ The `fix/cwe78-delete-via-ephemeral-shell-injection` branch was the right diagno
Both CWEs are fully resolved on both branches. The regression branch is superseded and must not be merged as-is.
**UPDATE 2026-04-22**: Commit `49ab614` ("CWE-78/CWE-22 — block shell injection") introduced an F1085 regression by changing the rm concat form `"/configs/" + filePath` to the unscoped 2-arg form `"/configs", filePath`. This was subsequently fixed in commit `a432df5` (branch `f1085-fix`). Both the concat form and `validateRelPath` defence-in-depth are now in place. The 2-arg form must not be re-introduced.
### Verification (staging `ce2491e`)
`copyFilesToContainer` (container_files.go:73-99):
@ -238,8 +240,11 @@ header := &tar.Header{Name: safeName, ...} ✅
`deleteViaEphemeral` (container_files.go:152-168):
```go
validateRelPath(filePath) ✅
Cmd: []string{"rm", "-rf", "/configs", filePath} ✅ exec form, no shell interpolation
validateRelPath(filePath) ✅ defence-in-depth against CWE-22
// NOTE: 2-arg "/configs", filePath form has F1085 (volume scope) defect.
// Correct form: "/configs/" + filePath (single concat arg, rm only touches
// files inside /configs). The 2-arg form passes /configs as an rm target,
// so rm -rf /configs attempts to delete the entire volume mount.
```
---

View File

@ -171,7 +171,7 @@ func (h *TemplatesHandler) deleteViaEphemeral(ctx context.Context, volumeName, f
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, "")