send_file: resolve home's symlinks before the "under home" check
Check resolved symlinks in the file path but compared it to s.Home as given, so a home reached through a symlink rejected its own files. Seen when tools_test ran on NativeLink, whose work dir is under the /var/lib/nativelink -> private/nativelink symlink. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0119iKoN3fSvRGUAYHupPW4U
This commit is contained in:
1 parent
af249326e8
commit
8c83a3316a
2 files changed
+21
-1
No files matched your search
@@ -49,3 +49,19 @@ func TestSendFileTool(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckSymlinkedHome(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
os.Mkdir(filepath.Join(dir, "real"), 0o755)
|
||||
os.WriteFile(filepath.Join(dir, "real", "chart.png"), []byte("png"), 0o644)
|
||||
os.Symlink(filepath.Join(dir, "real"), filepath.Join(dir, "home"))
|
||||
os.Symlink("/etc/passwd", filepath.Join(dir, "real", "escape"))
|
||||
s := &Server{Home: filepath.Join(dir, "home"), MaxMB: 1}
|
||||
|
||||
if err := s.Check("chart.png"); err != nil {
|
||||
t.Fatalf("file under a symlinked home: %v", err)
|
||||
}
|
||||
if err := s.Check("escape"); err == nil || !strings.Contains(err.Error(), "isn't under") {
|
||||
t.Fatalf("escape: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user