siyuan-note/siyuan · error
invalid content template path
Error message
invalid content template path
What it means
Returned by resolveDocContentTemplatePath (template.go:710) when the supplied template path is structurally invalid: empty, '.', '..', an absolute path, or begins with '..' + os.PathSeparator. This is the first-layer guard before any filesystem resolution, rejecting obviously unsafe or meaningless paths.
Source
Thrown at kernel/model/template.go:710
tree.Root.AppendChild(child)
}
templateIALs := parse.IAL2Map(templateTree.Root.KramdownIAL)
for key, value := range templateIALs {
if "name" == key || "alias" == key || "bookmark" == key || "memo" == key || "icon" == key ||
strings.HasPrefix(key, "custom-") {
tree.Root.SetIALAttr(key, value)
}
}
tree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
return indexWriteTreeUpsertQueue(tree)
}
func resolveDocContentTemplatePath(templatePath string) (string, error) {
templatePath = strings.TrimPrefix(filepath.ToSlash(strings.TrimSpace(templatePath)), "/")
cleanPath := filepath.Clean(filepath.FromSlash(templatePath))
if "" == cleanPath || "." == cleanPath || filepath.IsAbs(cleanPath) || ".." == cleanPath ||
strings.HasPrefix(cleanPath, ".."+string(os.PathSeparator)) {
return "", errors.New("invalid content template path")
}
templateRoot := filepath.Join(util.DataDir, "templates")
absPath := filepath.Join(templateRoot, cleanPath)
if !gulu.File.IsSubPath(templateRoot, absPath) {
return "", errors.New("content template path is outside templates directory")
}
if !filelock.IsExist(absPath) {
return "", fmt.Errorf("content template [%s] not found", templatePath)
}
realRoot, err := filepath.EvalSymlinks(templateRoot)
if nil != err {
return "", err
}
realPath, err := filepath.EvalSymlinks(absPath)
if nil != err {
return "", err
}
info, err := os.Stat(realPath)View on GitHub (pinned to 251596fc0d)
Solutions
- Set the document's content template path to a relative path under templates/ (e.g. 'diary.md').
- Strip leading slashes and '..' segments before saving the path.
- If the path is intentionally empty (no template), clear the setting rather than passing '.' or '/'.
Example fix
// before — absolute/empty path rejected
resolveDocContentTemplatePath("/home/user/tpl.md")
resolveDocContentTemplatePath("")
// after — relative path under templates/
resolveDocContentTemplatePath("diary.md") Defensive patterns
Strategy: validation
Validate before calling
import "path/filepath"
import "strings"
func isValidContentTemplatePath(p string) bool {
p = strings.TrimSpace(filepath.ToSlash(p))
p = strings.TrimPrefix(p, "/")
if p == "" || p == "." || p == ".." || filepath.IsAbs(p) || strings.HasPrefix(p, "../") {
return false
}
return true
} Prevention
- Store content template paths as relative paths under templates/ only.
- Reject empty, dot, absolute, and '..'-prefixed paths in the UI before saving.
- Treat the content-template path field as untrusted input.
When it happens
Trigger: A document's content-template frontmatter / setting specifies a path that is empty, a lone dot, an absolute path (e.g. '/etc/passwd' or 'C:\x'), or begins with parent traversal ('../'). Triggered when SiYuan resolves which template file to use for rendering a doc's initial content.
Common situations: A doc config saves an empty template path; a user manually edits the template path to an absolute OS path; a migration/import left a '.' placeholder; a path was constructed by joining user input that resolved to '..'.
Related errors
- path escapes templates dir: %s
- template path is outside templates directory
- content template path is outside templates directory
- path [%s] must not contain '..'
- path [%s] escapes box directory
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/ec0b35c6326aa3ab.
Report an issue: GitHub.