siyuan-note/siyuan · error

invalid skill resource path

Error message

invalid skill resource path: %s

What it means

normalizeSkillResourcePath validates the relative resource part of a skill locator before any file access. It rejects paths that are absolute, escape the skill directory via '..' components, are Windows drive- or volume-qualified, or normalize to '.', preventing path traversal outside the skill root.

Solutions

  1. Use plain relative paths inside the skill directory, e.g. 'skills/readme.md'
  2. Strip leading slashes, drive letters, and any '..' segments from the requested path before building the locator
  3. Normalize backslashes and clean the path client-side, then re-check it is still relative and non-escaping
  4. Sanitize or reject user-supplied resource names at the API boundary

Example fix

// before
util.LoadSkill("my-skill/../../../etc/passwd", enabled) // invalid skill resource path
// after
resource := path.Clean(strings.ReplaceAll(userInput, "\\", "/"))
if path.IsAbs(resource) || strings.HasPrefix(resource, "../") || resource == ".." || resource == "." {
  return errors.New("resource must be relative")
}
util.LoadSkill("my-skill/"+resource, enabled)
Defensive patterns

Strategy: validation

Validate before calling

func safeSkillResource(input string) (string, error) {
  cleaned := path.Clean(strings.ReplaceAll(input, "\\", "/"))
  if cleaned == "." || path.IsAbs(cleaned) || cleaned == ".." || strings.HasPrefix(cleaned, "../") {
    return "", fmt.Errorf("resource must be a relative path inside the skill")
  }
  return cleaned, nil
}

Prevention

When it happens

Trigger: LoadSkill with a locator whose resource part contains '..', a leading '/', a backslash-converted absolute path, a drive prefix like 'C:\', or a Windows volume name — anything failing the clean/abs/traversal checks.

Common situations: Constructing locators by naive string concatenation with user input; copying Windows-style paths with drive letters; accidental '../' in template-generated resource references.

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/d6b6a82fb945d08b. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/skill.go:289

	}
	result.Content = content
	result.ResourcePath = resource
	return result, nil
}

func splitSkillLocator(locator string) (name, resource string) {
	locator = strings.TrimSpace(strings.ReplaceAll(locator, `\`, "/"))
	name, resource, _ = strings.Cut(locator, "/")
	return
}

func normalizeSkillResourcePath(resource string) (string, error) {
	resource = strings.ReplaceAll(resource, `\`, "/")
	cleaned := path.Clean(resource)
	native := filepath.FromSlash(cleaned)
	if cleaned == "." || path.IsAbs(cleaned) || cleaned == ".." || strings.HasPrefix(cleaned, "../") ||
		filepath.IsAbs(native) || filepath.VolumeName(native) != "" || hasWindowsDrivePrefix(cleaned) {
		return "", fmt.Errorf("invalid skill resource path: %s", resource)
	}
	return cleaned, nil
}

func hasWindowsDrivePrefix(resource string) bool {
	if len(resource) < 2 || resource[1] != ':' {
		return false
	}
	drive := resource[0]
	return 'a' <= drive && drive <= 'z' || 'A' <= drive && drive <= 'Z'
}

func listSkillResources(skillDir string) (resources []string, truncated bool) {
	realRoot, err := filepath.EvalSymlinks(skillDir)
	if err != nil {
		return nil, false
	}

View on GitHub (pinned to 9f775e8a12)