fix: reject profile diagnostic symlink ancestors

This commit is contained in:
proxyctl coordinator
2026-07-17 11:41:55 +08:00
parent 6cb4943a54
commit e9ff24e04a
4 changed files with 166 additions and 20 deletions
+30
View File
@@ -105,6 +105,36 @@ func TestDoctorReturnsFailureWhenAnyCheckFails(t *testing.T) {
}
}
func TestDoctorProfileValidityRejectsSymlinkWithoutValidatingTarget(t *testing.T) {
victim := filepath.Join(t.TempDir(), "victim.json")
const content = "target content that is deliberately not JSON"
if err := os.WriteFile(victim, []byte(content), 0o640); err != nil {
t.Fatal(err)
}
directory := t.TempDir()
path := filepath.Join(directory, "profiles.json")
if err := os.Symlink(victim, path); err != nil {
t.Fatal(err)
}
var output bytes.Buffer
err := runMaintenanceCommand([]string{"doctor"}, strings.NewReader(""), &output, profile.NewFileStore(path), nil, nil, nil, nil)
text := output.String()
if err == nil || !strings.Contains(text, "[FAIL] Profile validity") {
t.Fatalf("doctor symlink result err=%v output=%q", err, text)
}
if strings.Contains(text, "parse Profile configuration") || strings.Contains(text, content) {
t.Fatalf("doctor read or validated symlink target: %q", text)
}
got, readErr := os.ReadFile(victim)
if readErr != nil {
t.Fatal(readErr)
}
if string(got) != content {
t.Fatalf("doctor changed victim content to %q", got)
}
}
func TestDoctorStorageAuthorityRejectsSymlinkedPathsWithoutTouchingVictim(t *testing.T) {
for _, test := range []struct {
name string