fix(CTRL-001): reject path traversal in .fab import manifest

manifest.AppName / HDDSubdirs / VolumeNames are attacker-controlled JSON inside
an imported .fab and reach filepath.Join+MkdirAll/extractTar with a trusted base
(restore.go:339/606/678). UnmarshalManifest did zero validation, so '../..' in
any of them escaped the stacks / HDD destination dir.

- New appexport.ValidateSegment + validateManifestPaths; UnmarshalManifest now
  fails the parse on a traversal segment (the chokepoint).
- Defence-in-depth ValidateSegment guards at the HDD-subdir and volume-name join
  loops in restore.go.
- ConfigFiles deliberately NOT validated (holds dotfiles like .felhom.yml; never
  used in a restore join).
- Permanent regression test (was the deep-sweep failing audit test) now asserts
  rejection of traversal + acceptance of legit names.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-13 19:09:47 +02:00
parent eea235bd69
commit c20ff56e4a
4 changed files with 164 additions and 0 deletions
@@ -38,5 +38,11 @@ func UnmarshalManifest(data []byte) (*Manifest, error) {
if err := json.Unmarshal(data, &m); err != nil {
return nil, err
}
// [CTRL-001] Reject path-traversal in any segment used to build a filesystem
// path on import (app_name, hdd_subdirs, volume_names). A hostile .fab must
// fail to parse rather than escape the stacks / HDD destination dir.
if err := validateManifestPaths(&m); err != nil {
return nil, err
}
return &m, nil
}