Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(selfupdate): reject any '..' sequence in archive entry names

Claude39523c9cf486
diff --git a/cli/beacon/internal/endpoint/selfupdate/fsutil.go b/cli/beacon/internal/endpoint/selfupdate/fsutil.go
index 56852928..cef8b97e 100644
--- a/cli/beacon/internal/endpoint/selfupdate/fsutil.go
+++ b/cli/beacon/internal/endpoint/selfupdate/fsutil.go
@@ -36,17 +36,17 @@ func acquireLock(path string) (func(), error) {
// safeJoin resolves an archive entry name against dest and rejects anything that
// would escape dest (path traversal / "zip slip"). It rejects absolute paths,
-// any ".." path segment (including backslash-separated ones), and any entry
-// whose cleaned, joined path is not contained within dest.
+// any name containing a ".." sequence (stricter than rejecting only ".."
+// segments, which is fine because release archives never carry ".." in entry
+// names, and a direct check on the raw name is what taint analyzers recognize
+// as a sanitizer), and any entry whose cleaned, joined path is not contained
+// within dest.
func safeJoin(dest, name string) (string, error) {
if filepath.IsAbs(name) || strings.HasPrefix(name, "/") || strings.HasPrefix(name, "\\") {
return "", fmt.Errorf("absolute path in archive entry: %q", name)
}
- normalized := strings.ReplaceAll(name, "\\", "/")
- for _, seg := range strings.Split(normalized, "/") {
- if seg == ".." {
- return "", fmt.Errorf("path traversal in archive entry: %q", name)
- }
+ if strings.Contains(name, "..") {
+ return "", fmt.Errorf("path traversal in archive entry: %q", name)
}
cleanDest := filepath.Clean(dest)
target := filepath.Clean(filepath.Join(cleanDest, name))
diff --git a/cli/beacon/internal/endpoint/selfupdate/fsutil_test.go b/cli/beacon/internal/endpoint/selfupdate/fsutil_test.go
index 6fd8af60..ba695d23 100644
--- a/cli/beacon/internal/endpoint/selfupdate/fsutil_test.go
+++ b/cli/beacon/internal/endpoint/selfupdate/fsutil_test.go
@@ -21,6 +21,7 @@ func TestSafeJoinRejectsTraversal(t *testing.T) {
"a/..",
"a\\..\\..\\escape",
"..\\escape",
+ "a..b",
"/etc/passwd",
"\\windows\\system32",
}