{"record":{"id":"1be3ad32fbbaa390","repo":"siyuan-note/siyuan","slug":"skill-resource-escapes-skill-directory-s","errorCode":null,"errorMessage":"skill resource escapes skill directory: %s","messagePattern":"skill resource escapes skill directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/util/skill.go","lineNumber":367,"sourceCode":"\t\ttruncated = true\n\t}\n\tsort.Strings(resources)\n\treturn resources, truncated\n}\n\nfunc readSkillResource(skillDir, skillName, resource string) (string, error) {\n\trealRoot, err := filepath.EvalSymlinks(skillDir)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"skill not found: %s\", skillName)\n\t}\n\n\ttarget := filepath.Join(realRoot, filepath.FromSlash(resource))\n\trealTarget, err := filepath.EvalSymlinks(target)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"skill resource not found: %s/%s\", skillName, resource)\n\t}\n\tif realTarget != realRoot && !gulu.File.IsSubPath(realRoot, realTarget) {\n\t\treturn \"\", fmt.Errorf(\"skill resource escapes skill directory: %s\", resource)\n\t}\n\n\tinfo, err := os.Stat(realTarget)\n\tif err != nil || !info.Mode().IsRegular() {\n\t\treturn \"\", fmt.Errorf(\"skill resource is not a regular file: %s/%s\", skillName, resource)\n\t}\n\tif info.Size() > maxSkillResourceBytes {\n\t\treturn \"\", fmt.Errorf(\"skill resource exceeds the %d byte limit: %s/%s\", maxSkillResourceBytes, skillName, resource)\n\t}\n\n\tfile, err := os.Open(realTarget)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"skill resource not found: %s/%s\", skillName, resource)\n\t}\n\tdefer file.Close()\n\tdata, err := io.ReadAll(io.LimitReader(file, maxSkillResourceBytes+1))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"skill resource read failed: %s/%s\", skillName, resource)","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/skill.go#L349-L385","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove ../ segments from the resource path so it stays inside the skill directory","Replace the out-of-tree symlink with a real copy of the file inside the skill directory","If legitimate shared data is needed, copy it into the skill at install time instead of linking","Use validateSkillName-sanitized names and normalized resource paths when constructing the request"],"exampleFix":"// before\nLoadSkill(\"my-skill\", \"../../conf/conf.json\")\n// after\nLoadSkill(\"my-skill\", \"reference/notes.md\") // path confined to the skill directory","handlingStrategy":"validation","validationCode":"func safeResource(resource string) bool {\n    clean := path.Clean(\"/\" + filepath.ToSlash(resource))\n    return !strings.Contains(clean, \"..\")\n}\nif !safeResource(resource) { return errors.New(\"resource escapes skill directory\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never build resource paths from unsanitized user input","Use path.Clean and reject any '..' segment before calling","Copy shared files into the skill instead of symlinking them","Audit imported skill archives for absolute or escaping links"],"tags":["skill","security","path-traversal"],"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"}