Handle relative system temporary directories
This commit is contained in:
@@ -255,7 +255,9 @@ candidate output still leaves the worktree clean.
|
||||
**Resolution:** Candidate and CLI delivery builds use shared system temporary
|
||||
storage allocated by `internal/tempdir`, with worktree containment checks and
|
||||
caller-owned cleanup. Regressions execute both operations with read-only
|
||||
repository parents and confirm clean worktrees. Affected suites pass.
|
||||
repository parents and confirm clean worktrees. Additional helper regressions
|
||||
cover relative system temporary paths and cleanup after rejecting in-worktree
|
||||
storage. Affected suites pass.
|
||||
|
||||
### R7 — Medium: Attachment origin restrictions exceed credential isolation
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ func Outside(repositoryDir, pattern string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
absolute, err := filepath.Abs(directory)
|
||||
if err != nil {
|
||||
os.RemoveAll(directory)
|
||||
return "", err
|
||||
}
|
||||
directory = absolute
|
||||
repository, err := filepath.Abs(repositoryDir)
|
||||
if err == nil && !strings.EqualFold(filepath.VolumeName(repository), filepath.VolumeName(directory)) {
|
||||
return directory, nil
|
||||
|
||||
52
internal/tempdir/tempdir_test.go
Normal file
52
internal/tempdir/tempdir_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package tempdir
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOutsideHonorsRelativeTemporaryDirectory(t *testing.T) {
|
||||
parent := t.TempDir()
|
||||
repository := t.TempDir()
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
relative, err := filepath.Rel(cwd, parent)
|
||||
if err != nil {
|
||||
t.Skip("temporary directory is on another volume")
|
||||
}
|
||||
setTemporaryDirectory(t, relative)
|
||||
directory, err := Outside(repository, "fixture-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(directory)
|
||||
if !filepath.IsAbs(directory) || filepath.Dir(directory) != parent {
|
||||
t.Fatalf("temporary storage=%q want parent %q", directory, parent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutsideRejectsAndCleansStorageInsideWorktree(t *testing.T) {
|
||||
repository := t.TempDir()
|
||||
setTemporaryDirectory(t, repository)
|
||||
if directory, err := Outside(repository, "fixture-"); err == nil {
|
||||
os.RemoveAll(directory)
|
||||
t.Fatal("storage created inside worktree")
|
||||
}
|
||||
remaining, err := os.ReadDir(repository)
|
||||
if err != nil || len(remaining) != 0 {
|
||||
t.Fatalf("temporary storage left behind: %v %v", remaining, err)
|
||||
}
|
||||
}
|
||||
|
||||
func setTemporaryDirectory(t *testing.T, directory string) {
|
||||
t.Helper()
|
||||
variable := "TMPDIR"
|
||||
if runtime.GOOS == "windows" {
|
||||
variable = "TMP"
|
||||
}
|
||||
t.Setenv(variable, directory)
|
||||
}
|
||||
Reference in New Issue
Block a user