Harden core snapshot sync and workspace lifecycle
This commit is contained in:
@@ -25,8 +25,7 @@ func IsReservedPath(relativePath string) bool {
|
||||
if cleaned == "" {
|
||||
return false
|
||||
}
|
||||
first := strings.Split(cleaned, "/")[0]
|
||||
return strings.EqualFold(first, ".verstak")
|
||||
return containsReservedSegment(cleaned)
|
||||
}
|
||||
|
||||
func normalizeRelativePath(input string, allowRoot bool) (string, error) {
|
||||
@@ -67,8 +66,16 @@ func IsReservedPathNoNormalize(cleaned string) bool {
|
||||
if cleaned == "" {
|
||||
return false
|
||||
}
|
||||
first := strings.Split(cleaned, "/")[0]
|
||||
return strings.EqualFold(first, ".verstak")
|
||||
return containsReservedSegment(cleaned)
|
||||
}
|
||||
|
||||
func containsReservedSegment(cleaned string) bool {
|
||||
for _, segment := range strings.Split(cleaned, "/") {
|
||||
if strings.EqualFold(segment, ".verstak") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func looksAbsolute(input string) bool {
|
||||
|
||||
@@ -43,6 +43,7 @@ func TestNormalizeRelativeFileRejectsUnsafePaths(t *testing.T) {
|
||||
".verstak/vault.json",
|
||||
"./.verstak",
|
||||
".verstak/trash",
|
||||
"Workspace/.verstak/workspace.json",
|
||||
"folder/../.verstak",
|
||||
".Verstak",
|
||||
}
|
||||
@@ -70,6 +71,9 @@ func TestReservedPathPolicy(t *testing.T) {
|
||||
if IsReservedPath("Notes/.verstak.md") {
|
||||
t.Fatal("Notes/.verstak.md should not be reserved")
|
||||
}
|
||||
if !IsReservedPath("Workspace/.verstak/workspace.json") {
|
||||
t.Fatal("nested .verstak should be reserved")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRelativeFileAcceptsOnlySlashSeparatedRelativePaths(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user