Harden debug bundle filesystem collaborators

This commit is contained in:
2026-07-18 13:42:17 +00:00
parent 9746a42e04
commit 7bcce9953e
4 changed files with 184 additions and 4 deletions

View File

@@ -39,3 +39,18 @@ func TestWriteBytesIsAtomicAndUsesRequestedModes(t *testing.T) {
}
}
}
func TestWriteBytesRejectsSymlinkedComponents(t *testing.T) {
root := t.TempDir()
outside := t.TempDir()
if err := os.Symlink(outside, filepath.Join(root, "link")); err != nil {
t.Skipf("symbolic links unavailable: %v", err)
}
if err := WriteBytes(root, "link/value", []byte("value"), 0o700, 0o600); err == nil {
t.Fatal("WriteBytes accepted a symlinked directory")
}
if _, err := os.Stat(filepath.Join(outside, "value")); !os.IsNotExist(err) {
t.Fatalf("write escaped through symlink: %v", err)
}
}