Confine local file installation paths
This commit is contained in:
@@ -431,6 +431,29 @@ func TestPromoteDirectoryRejectsDestinationInsideSource(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromoteDirectoryRejectsSymlinkedDestinationAncestor(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
source := filepath.Join(root, "source")
|
||||
if err := os.Mkdir(source, 0o755); err != nil {
|
||||
t.Fatalf("Mkdir(source) error = %v", err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(source, "value.txt"), []byte("source"), 0o644); err != nil {
|
||||
t.Fatalf("WriteFile(source) error = %v", err)
|
||||
}
|
||||
outside := t.TempDir()
|
||||
if err := os.Symlink(outside, filepath.Join(root, "redirect")); err != nil {
|
||||
t.Skipf("Symlink unavailable: %v", err)
|
||||
}
|
||||
|
||||
err := PromoteDirectory(source, filepath.Join(root, "redirect", "bundle"))
|
||||
if err == nil {
|
||||
t.Fatal("PromoteDirectory() error = nil, want symlink ancestor rejection")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(outside, "bundle")); !os.IsNotExist(err) {
|
||||
t.Fatalf("outside bundle exists: stat err = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func mustWriteFile(t *testing.T, path string, data []byte, mode os.FileMode) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user