From 8c83a3316a3af015e12c1c7fdf03f3cfcd2a7e3f Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Sun, 1 Nov 2026 20:30:39 -0500 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_0119iKoN3fSvRGUAYHupPW4U --- slackerbot/internal/tools/server.go | 6 +++++- slackerbot/internal/tools/server_test.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/slackerbot/internal/tools/server.go b/slackerbot/internal/tools/server.go index a9f64a7..2aabe23 100644 --- a/slackerbot/internal/tools/server.go +++ b/slackerbot/internal/tools/server.go @@ -247,7 +247,11 @@ func (s *Server) Check(path string) error { if err != nil { return fmt.Errorf("can't find %s", path) } - if !strings.HasPrefix(real, filepath.Clean(s.Home)+"/") { + home := filepath.Clean(s.Home) + if h, err := filepath.EvalSymlinks(home); err == nil { + home = h + } + if !strings.HasPrefix(real, home+"/") { return fmt.Errorf("%s isn't under %s; copy it there first", path, s.Home) } st, err := os.Stat(real) diff --git a/slackerbot/internal/tools/server_test.go b/slackerbot/internal/tools/server_test.go index e35e518..c81d619 100644 --- a/slackerbot/internal/tools/server_test.go +++ b/slackerbot/internal/tools/server_test.go @@ -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) + } +}