{"record":{"id":"d6b6a82fb945d08b","repo":"siyuan-note/siyuan","slug":"invalid-skill-resource-path-s","errorCode":null,"errorMessage":"invalid skill resource path: %s","messagePattern":"invalid skill resource path: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/skill.go","lineNumber":289,"sourceCode":"\t}\n\tresult.Content = content\n\tresult.ResourcePath = resource\n\treturn result, nil\n}\n\nfunc splitSkillLocator(locator string) (name, resource string) {\n\tlocator = strings.TrimSpace(strings.ReplaceAll(locator, `\\`, \"/\"))\n\tname, resource, _ = strings.Cut(locator, \"/\")\n\treturn\n}\n\nfunc normalizeSkillResourcePath(resource string) (string, error) {\n\tresource = strings.ReplaceAll(resource, `\\`, \"/\")\n\tcleaned := path.Clean(resource)\n\tnative := filepath.FromSlash(cleaned)\n\tif cleaned == \".\" || path.IsAbs(cleaned) || cleaned == \"..\" || strings.HasPrefix(cleaned, \"../\") ||\n\t\tfilepath.IsAbs(native) || filepath.VolumeName(native) != \"\" || hasWindowsDrivePrefix(cleaned) {\n\t\treturn \"\", fmt.Errorf(\"invalid skill resource path: %s\", resource)\n\t}\n\treturn cleaned, nil\n}\n\nfunc hasWindowsDrivePrefix(resource string) bool {\n\tif len(resource) < 2 || resource[1] != ':' {\n\t\treturn false\n\t}\n\tdrive := resource[0]\n\treturn 'a' <= drive && drive <= 'z' || 'A' <= drive && drive <= 'Z'\n}\n\nfunc listSkillResources(skillDir string) (resources []string, truncated bool) {\n\trealRoot, err := filepath.EvalSymlinks(skillDir)\n\tif err != nil {\n\t\treturn nil, false\n\t}\n","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/skill.go#L271-L307","documentation":"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.","triggerScenarios":"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.","commonSituations":"Constructing locators by naive string concatenation with user input; copying Windows-style paths with drive letters; accidental '../' in template-generated resource references.","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"],"exampleFix":"// before\nutil.LoadSkill(\"my-skill/../../../etc/passwd\", enabled) // invalid skill resource path\n// after\nresource := path.Clean(strings.ReplaceAll(userInput, \"\\\\\", \"/\"))\nif path.IsAbs(resource) || strings.HasPrefix(resource, \"../\") || resource == \"..\" || resource == \".\" {\n  return errors.New(\"resource must be relative\")\n}\nutil.LoadSkill(\"my-skill/\"+resource, enabled)","handlingStrategy":"validation","validationCode":"func safeSkillResource(input string) (string, error) {\n  cleaned := path.Clean(strings.ReplaceAll(input, \"\\\\\", \"/\"))\n  if cleaned == \".\" || path.IsAbs(cleaned) || cleaned == \"..\" || strings.HasPrefix(cleaned, \"../\") {\n    return \"\", fmt.Errorf(\"resource must be a relative path inside the skill\")\n  }\n  return cleaned, nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["path-traversal","security","skills","validation"],"backgroundTag":"path-traversal-blocked","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}