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
- Use plain relative paths inside the skill directory, e.g. 'skills/readme.md'
- Strip leading slashes, drive letters, and any '..' segments from the requested path before building the locator
- Normalize backslashes and clean the path client-side, then re-check it is still relative and non-escaping
- 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
- Only build locators from sanitized, relative resource names
- Never concatenate raw user input into 'name/resource' locators
- Strip drive letters and backslashes from Windows-originated paths
- Reject '..' segments at the API boundary, before they reach LoadSkill
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
- asset path escapes data directory
- asset path escapes data directory
- export path is outside export directory
- history path [ ] is not in workspace
- history path [ ] is not under history directory
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)