{"record":{"id":"ec7d22c70c32f69d","repo":"siyuan-note/siyuan","slug":"child-template-path-is-outside-the-current-templat","errorCode":null,"errorMessage":"child template path is outside the current template package","messagePattern":"child template path is outside the current template package","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":431,"sourceCode":"\t}\n\tabsPath := filepath.Join(packageRoot, cleanPath)\n\tif !gulu.File.IsSubPath(packageRoot, absPath) || !filelock.IsExist(absPath) {\n\t\treturn \"\", fmt.Errorf(\"child template [%s] not found in the current template package\", relativePath)\n\t}\n\trealRoot, err := filepath.EvalSymlinks(packageRoot)\n\tif nil != err {\n\t\treturn \"\", err\n\t}\n\trealPath, err := filepath.EvalSymlinks(absPath)\n\tif nil != err {\n\t\treturn \"\", err\n\t}\n\tinfo, err := os.Stat(realPath)\n\tif nil != err || !info.Mode().IsRegular() {\n\t\treturn \"\", fmt.Errorf(\"child template [%s] is not a regular file\", relativePath)\n\t}\n\tif !gulu.File.IsSubPath(realRoot, realPath) {\n\t\treturn \"\", errors.New(\"child template path is outside the current template package\")\n\t}\n\treturn realPath, nil\n}\n\nfunc templateDocTreeDataModel(node *TemplateDocTreeNode) map[string]string {\n\treturn map[string]string{\n\t\t\"title\":    node.Title,\n\t\t\"id\":       node.ID,\n\t\t\"parentID\": node.ParentID,\n\t\t\"rootID\":   node.RootID,\n\t\t\"hPath\":    node.HPath,\n\t\t\"name\":     \"\",\n\t\t\"alias\":    \"\",\n\t}\n}\n\n// AttachTemplateDocTreePlans 将一次性计划转换为内核事务操作，父文档内容与全部子文档共用一条撤销记录。\nfunc AttachTemplateDocTreePlans(transactions []*Transaction) (attached bool, err error) {","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L413-L449","documentation":"After resolving symlinks, resolveTemplatePackageFile verifies the real path still lies inside the template package root. This error is thrown when a symlink (or other path trickery) causes the child template to resolve outside the package directory. It blocks path escape from the template sandbox.","triggerScenarios":"A child template path inside a package contains a symlink whose resolved target is outside data/templates/<package>/, e.g. ../../elsewhere/template.md, so gulu.File.IsSubPath(realRoot, realPath) fails.","commonSituations":"Template packages downloaded from the marketplace contain symlinks to external files; a developer symlinks a shared template folder into a package; syncing packages between machines where symlinks point elsewhere.","solutions":["Replace the symlink with a real copy of the target file inside the template package","Move the referenced file into the package so no symlink escape is needed","Verify with filepath.EvalSymlinks that the resolved path stays under the package root"],"exampleFix":"// before\nln -s ../../shared/template.md templates/pkg/template.md\n// after\ncp ../../shared/template.md templates/pkg/template.md","handlingStrategy":"validation","validationCode":"const real = await evalSymlinks(path)\nassert(isSubPath(packageRoot, real), 'child template escapes package')","typeGuard":"function staysInPackage(realRoot, realPath) { return realPath.startsWith(realRoot + '/'); }","tryCatchPattern":"try { resolveTemplatePackageFile(rel, root) } catch (e) { if (String(e).includes('outside the current template package')) { replaceSymlinkWithCopy(rel) } else { throw e } }","preventionTips":["Never ship template packages containing symlinks","Copy shared templates into the package instead of linking","Re-check packages after extracting from archives that may have rewired symlinks"],"tags":["security","symlink","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"}