siyuan-note/siyuan · warning

skill resource escapes skill directory

Error message

skill resource escapes skill directory: %s

What it means

After resolving symlinks, readSkillResource checks that the resolved target is the skill root itself or lies underneath it via gulu.File.IsSubPath. If the resolved path falls outside the skill directory, the read is rejected as a path-escape attempt to prevent skills from reading arbitrary files outside their sandbox.

Solutions

  1. Remove ../ segments from the resource path so it stays inside the skill directory
  2. Replace the out-of-tree symlink with a real copy of the file inside the skill directory
  3. If legitimate shared data is needed, copy it into the skill at install time instead of linking
  4. Use validateSkillName-sanitized names and normalized resource paths when constructing the request

Example fix

// before
LoadSkill("my-skill", "../../conf/conf.json")
// after
LoadSkill("my-skill", "reference/notes.md") // path confined to the skill directory
Defensive patterns

Strategy: validation

Validate before calling

func safeResource(resource string) bool {
    clean := path.Clean("/" + filepath.ToSlash(resource))
    return !strings.Contains(clean, "..")
}
if !safeResource(resource) { return errors.New("resource escapes skill directory") }

Prevention

When it happens

Trigger: A resource path contains ../ segments that climb out of the skill root, or a symlink inside the skill directory points to a location outside it, and LoadSkill/readSkillResource is called with that resource.

Common situations: Hand-edited skill directories containing symlinks to shared files elsewhere on disk; programmatically generated resource paths with insufficient sanitization; importing skills from untrusted archives that embed escaping links.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/1be3ad32fbbaa390. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/skill.go:367

		truncated = true
	}
	sort.Strings(resources)
	return resources, truncated
}

func readSkillResource(skillDir, skillName, resource string) (string, error) {
	realRoot, err := filepath.EvalSymlinks(skillDir)
	if err != nil {
		return "", fmt.Errorf("skill not found: %s", skillName)
	}

	target := filepath.Join(realRoot, filepath.FromSlash(resource))
	realTarget, err := filepath.EvalSymlinks(target)
	if err != nil {
		return "", fmt.Errorf("skill resource not found: %s/%s", skillName, resource)
	}
	if realTarget != realRoot && !gulu.File.IsSubPath(realRoot, realTarget) {
		return "", fmt.Errorf("skill resource escapes skill directory: %s", resource)
	}

	info, err := os.Stat(realTarget)
	if err != nil || !info.Mode().IsRegular() {
		return "", fmt.Errorf("skill resource is not a regular file: %s/%s", skillName, resource)
	}
	if info.Size() > maxSkillResourceBytes {
		return "", fmt.Errorf("skill resource exceeds the %d byte limit: %s/%s", maxSkillResourceBytes, skillName, resource)
	}

	file, err := os.Open(realTarget)
	if err != nil {
		return "", fmt.Errorf("skill resource not found: %s/%s", skillName, resource)
	}
	defer file.Close()
	data, err := io.ReadAll(io.LimitReader(file, maxSkillResourceBytes+1))
	if err != nil {
		return "", fmt.Errorf("skill resource read failed: %s/%s", skillName, resource)

View on GitHub (pinned to 9f775e8a12)