Skip to content

Commit 7783f0c

Browse files
JAORMXclaude
andcommitted
Guard InjectVMConfig symlink-rejection via delegation chain
InjectVMConfig writes /etc/go-microvm.json by delegating to InjectFile, which now refuses symlink components. A regression test locks the guarantee in at the delegation boundary so a future refactor that inlines or bypasses InjectFile cannot silently lose the protection. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7e81e1f commit 7783f0c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

hooks/hooks_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ func TestInjectVMConfig(t *testing.T) {
9393
}
9494
}
9595

96+
func TestInjectVMConfig_RejectsSymlinkComponents(t *testing.T) {
97+
t.Parallel()
98+
99+
// Guard the delegation chain: InjectVMConfig -> InjectFile.
100+
// If InjectFile's symlink safety regresses, this test catches it.
101+
rootfs := t.TempDir()
102+
outside := t.TempDir()
103+
stageSymlink(t, rootfs, "etc", outside)
104+
105+
hook := InjectVMConfig(vmconfig.Config{TmpSizeMiB: 512})
106+
err := hook(rootfs, nil)
107+
require.Error(t, err)
108+
assert.Contains(t, err.Error(), "symlink")
109+
110+
_, statErr := os.Stat(filepath.Join(outside, "go-microvm.json"))
111+
assert.True(t, os.IsNotExist(statErr), "must not write under symlink target")
112+
}
113+
96114
func TestInjectFile_WritesContent(t *testing.T) {
97115
t.Parallel()
98116

0 commit comments

Comments
 (0)