The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Read Beacon's skill marker safely and only in user skill directories
Claude1095f33a18ed
diff --git a/cli/beacon/internal/agentskills/agentskills.go b/cli/beacon/internal/agentskills/agentskills.goindex 10ba750b..1cb1bd19 100644--- a/cli/beacon/internal/agentskills/agentskills.go+++ b/cli/beacon/internal/agentskills/agentskills.go@@ -13,6 +13,7 @@ import ("embed""errors""fmt"+ "io""io/fs""os""path"@@ -160,7 +161,7 @@ func inspect(dir string) (managed, exists bool, err error) {// A symlink or a file: something the person set up. Never followed or replaced.return false, true, nil}- data, err := os.ReadFile(filepath.Join(dir, MarkerFile))+ data, err := readMarker(filepath.Join(dir, MarkerFile))if errors.Is(err, os.ErrNotExist) {return false, true, nil}@@ -170,6 +171,28 @@ func inspect(dir string) (managed, exists bool, err error) {return string(data) == markerContent, true, nil}+// readMarker reads a marker Beacon could have written: a regular file, never followed through+// a symlink, and read no further than the marker's own length. Anything else (a symlink, a+// FIFO, a device, an oversized file) is not Beacon's marker.+func readMarker(name string) ([]byte, error) {+ info, err := os.Lstat(name)+ if err != nil {+ return nil, err+ }+ if !info.Mode().IsRegular() || info.Size() > int64(len(markerContent)) {+ return nil, nil+ }+ f, err := os.Open(name)+ if err != nil {+ return nil, err+ }+ defer f.Close()+ if opened, err := f.Stat(); err != nil || !os.SameFile(info, opened) {+ return nil, err+ }+ return io.ReadAll(io.LimitReader(f, int64(len(markerContent))+1))+}+// files lists one embedded skill's files, as slash paths relative to the skill directory.func files(name string) ([]string, error) {var out []stringdiff --git a/cli/beacon/internal/agentskills/agentskills_test.go b/cli/beacon/internal/agentskills/agentskills_test.goindex 5f9ad946..cf97bbcb 100644--- a/cli/beacon/internal/agentskills/agentskills_test.go+++ b/cli/beacon/internal/agentskills/agentskills_test.go@@ -162,3 +162,48 @@ func TestRootsAddClaudeOnlyWhenClaudeIsSetUp(t *testing.T) {t.Fatalf("roots = %v", roots)}}++func TestManagedReadsOnlyARegularMarker(t *testing.T) {+ root := t.TempDir()+ for _, r := range Install([]string{root}) {+ if r.Err != nil {+ t.Fatal(r.Err)+ }+ }+ name := Names()[0]+ if !Managed(filepath.Join(root, name)) {+ t.Fatal("Beacon's own skill was not recognized")+ }++ skill := func(t *testing.T) string {+ dir := filepath.Join(t.TempDir(), name)+ if err := os.MkdirAll(dir, 0o755); err != nil {+ t.Fatal(err)+ }+ return dir+ }+ t.Run("oversized", func(t *testing.T) {+ dir := skill(t)+ if err := os.WriteFile(filepath.Join(dir, MarkerFile), []byte(markerContent+strings.Repeat("x", 1<<20)), 0o644); err != nil {+ t.Fatal(err)+ }+ if Managed(dir) {+ t.Error("an oversized marker was taken for Beacon's")+ }+ })+ t.Run("symlinked", func(t *testing.T) {+ dir := skill(t)+ // A link to a genuine marker is still not followed, and a link to a device that never+ // ends must not be read at all.+ for _, target := range []string{filepath.Join(root, name, MarkerFile), "/dev/zero"} {+ link := filepath.Join(dir, MarkerFile)+ _ = os.Remove(link)+ if err := os.Symlink(target, link); err != nil {+ t.Skipf("symlinks unavailable: %v", err)+ }+ if Managed(dir) {+ t.Errorf("a marker linked to %s was taken for Beacon's", target)+ }+ }+ })+}diff --git a/cli/beacon/internal/mcpserver/intel_tools.go b/cli/beacon/internal/mcpserver/intel_tools.goindex 5832721c..e6787317 100644--- a/cli/beacon/internal/mcpserver/intel_tools.go+++ b/cli/beacon/internal/mcpserver/intel_tools.go@@ -267,14 +267,15 @@ func (s *Server) checkInstalled(ctx context.Context, args map[string]interface{}}// beaconSkill reports whether an inventoried skill is one Beacon installed: one of its skill-// names, in a directory carrying Beacon's marker.+// names, in a user-level directory carrying Beacon's marker. Beacon never installs project+// skills, so a repository's own skill directories are never taken for Beacon's or read for it.func beaconSkill(names []string) func(inventory.Skill) bool {known := map[string]bool{}for _, name := range names {known[name] = true}return func(s inventory.Skill) bool {- return known[strings.TrimSpace(s.SkillName)] && s.ManifestPath != "" && agentskills.Managed(filepath.Dir(s.ManifestPath))+ return known[strings.TrimSpace(s.SkillName)] && s.SourceScope == inventory.ScopeUser && s.ManifestPath != "" && agentskills.Managed(filepath.Dir(s.ManifestPath))}}diff --git a/cli/beacon/internal/mcpserver/intel_tools_test.go b/cli/beacon/internal/mcpserver/intel_tools_test.goindex 2d36c739..53e0ee60 100644--- a/cli/beacon/internal/mcpserver/intel_tools_test.go+++ b/cli/beacon/internal/mcpserver/intel_tools_test.go@@ -495,13 +495,19 @@ func TestBeaconSkillNeedsBeaconsMarker(t *testing.T) {t.Fatal(err)}isBeacon := beaconSkill(names)- if !isBeacon(inventory.Skill{SkillName: names[0], ManifestPath: filepath.Join(root, names[0], "SKILL.md")}) {+ user := inventory.ScopeUser+ if !isBeacon(inventory.Skill{SkillName: names[0], SourceScope: user, ManifestPath: filepath.Join(root, names[0], "SKILL.md")}) {t.Error("Beacon's installed skill was not recognized")}- if isBeacon(inventory.Skill{SkillName: names[0], ManifestPath: filepath.Join(other, "SKILL.md")}) {+ if isBeacon(inventory.Skill{SkillName: names[0], SourceScope: user, ManifestPath: filepath.Join(other, "SKILL.md")}) {t.Error("a skill that only shares Beacon's name was taken for Beacon's")}- if isBeacon(inventory.Skill{SkillName: "pdf", ManifestPath: filepath.Join(root, names[0], "SKILL.md")}) {+ if isBeacon(inventory.Skill{SkillName: "pdf", SourceScope: user, ManifestPath: filepath.Join(root, names[0], "SKILL.md")}) {t.Error("a skill with another name was taken for Beacon's")}+ // Beacon never installs project skills, so a repository's skill directory is never read for+ // a marker, even one that carries a genuine copy.+ if isBeacon(inventory.Skill{SkillName: names[0], SourceScope: inventory.ScopeProject, ManifestPath: filepath.Join(root, names[0], "SKILL.md")}) {+ t.Error("a project skill was taken for Beacon's")+ }}