mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
* fix(plugin): trust symlinked ancestors of the Agent config root (#365) noSymlink walked every ancestor up to / and refused the write if any was a link, so macOS /var, a home on a linked volume, a dotfiles-linked ~/.pi, or a PI_CODING_AGENT_DIR / CLAUDE_CONFIG_DIR / CODEX_HOME behind a link failed with "refusing to modify symlinked native path". noSymlink now takes the root the user chose (the Agent folder, the project, or Skillshare's state dir) and checks only the path and the folders between it and that root, refusing paths outside it. The root is compared lexically because every checked path is built by joining onto it, so no EvalSymlinks call is needed. A linked config file or a linked folder inside the root is still refused, and Windows junctions are still detected via IsLinkMode. * fix(plugin): bound the noSymlink ancestor walk by its relative depth The walk stopped when p equalled root, but on Windows Dir spells a UNC share root with a trailing separator (\\server\share\) while Clean keeps the root without it, so the loop never ended for a PI_CODING_AGENT_DIR, project root or StateDir on a share root. Walk up exactly as many levels as the relative path has instead.
52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
package plugin
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// A config root reached through a linked ancestor (macOS /var, a linked home or
|
|
// CLAUDE_CONFIG_DIR) is the user's choice; links inside the root are refused.
|
|
func TestNoSymlinkTrustsOnlyTheRootAndAbove(t *testing.T) {
|
|
base := t.TempDir()
|
|
volume := filepath.Join(base, "volume")
|
|
outside := filepath.Join(base, "outside")
|
|
for _, dir := range []string{filepath.Join(volume, "agent", "real"), outside} {
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
link := func(target, name string) {
|
|
t.Helper()
|
|
if err := os.Symlink(target, name); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
linked := filepath.Join(base, "linked")
|
|
link(volume, linked)
|
|
root := filepath.Join(linked, "agent")
|
|
link(filepath.Join(outside, "settings.json"), filepath.Join(root, "settings.json"))
|
|
link(outside, filepath.Join(root, "plugins"))
|
|
linkedRoot := filepath.Join(base, "linked-agent")
|
|
link(filepath.Join(volume, "agent"), linkedRoot)
|
|
|
|
for _, tc := range []struct {
|
|
name, root, path string
|
|
ok bool
|
|
}{
|
|
{"linked ancestor", root, filepath.Join(root, "real", "config.json"), true},
|
|
{"linked root", linkedRoot, filepath.Join(linkedRoot, "real", "config.json"), true},
|
|
{"missing path", root, filepath.Join(root, "new", "config.json"), true},
|
|
{"linked config file", root, filepath.Join(root, "settings.json"), false},
|
|
{"linked folder inside root", root, filepath.Join(root, "plugins", "demo"), false},
|
|
{"outside root", root, filepath.Join(base, "volume", "other.json"), false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if err := noSymlink(tc.root, tc.path); (err == nil) != tc.ok {
|
|
t.Fatalf("noSymlink(%s, %s) = %v", tc.root, tc.path, err)
|
|
}
|
|
})
|
|
}
|
|
}
|