siyuan-note/siyuan · error
child template path is outside the current template package
Error message
child template path is outside the current template package
What it means
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.
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
Example fix
// before ln -s ../../shared/template.md templates/pkg/template.md // after cp ../../shared/template.md templates/pkg/template.md
Defensive patterns
Strategy: validation
Validate before calling
const real = await evalSymlinks(path) assert(isSubPath(packageRoot, real), 'child template escapes package')
Type guard
function staysInPackage(realRoot, realPath) { return realPath.startsWith(realRoot + '/'); } Try / catch
try { resolveTemplatePackageFile(rel, root) } catch (e) { if (String(e).includes('outside the current template package')) { replaceSymlinkWithCopy(rel) } else { throw e } } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- archive entry resolves outside destination
- asset path resolves outside assets directory
- notebook asset path resolves outside notebook directory
- symlink [ ] resolves outside data/assets: [ ]
- symlink [ ] resolves outside workspace: [ ]
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/ec7d22c70c32f69d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:431
}
absPath := filepath.Join(packageRoot, cleanPath)
if !gulu.File.IsSubPath(packageRoot, absPath) || !filelock.IsExist(absPath) {
return "", fmt.Errorf("child template [%s] not found in the current template package", relativePath)
}
realRoot, err := filepath.EvalSymlinks(packageRoot)
if nil != err {
return "", err
}
realPath, err := filepath.EvalSymlinks(absPath)
if nil != err {
return "", err
}
info, err := os.Stat(realPath)
if nil != err || !info.Mode().IsRegular() {
return "", fmt.Errorf("child template [%s] is not a regular file", relativePath)
}
if !gulu.File.IsSubPath(realRoot, realPath) {
return "", errors.New("child template path is outside the current template package")
}
return realPath, nil
}
func templateDocTreeDataModel(node *TemplateDocTreeNode) map[string]string {
return map[string]string{
"title": node.Title,
"id": node.ID,
"parentID": node.ParentID,
"rootID": node.RootID,
"hPath": node.HPath,
"name": "",
"alias": "",
}
}
// AttachTemplateDocTreePlans 将一次性计划转换为内核事务操作,父文档内容与全部子文档共用一条撤销记录。
func AttachTemplateDocTreePlans(transactions []*Transaction) (attached bool, err error) {View on GitHub (pinned to 9f775e8a12)