{"record":{"id":"55f376f4c9565a09","repo":"siyuan-note/siyuan","slug":"staged-document-tree-contains-a-symbolic-link","errorCode":null,"errorMessage":"staged document tree contains a symbolic link","messagePattern":"staged document tree contains a symbolic link","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/import_obsidian.go","lineNumber":2437,"sourceCode":"\nfunc copyObsidianTreeFiles(sourceRoot, destinationRoot string) error {\n\treturn filepath.WalkDir(sourceRoot, func(current string, entry fs.DirEntry, walkErr error) error {\n\t\tif walkErr != nil {\n\t\t\treturn walkErr\n\t\t}\n\t\trel, err := filepath.Rel(sourceRoot, current)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif rel == \".\" {\n\t\t\treturn nil\n\t\t}\n\t\tdestination := filepath.Join(destinationRoot, rel)\n\t\tif entry.IsDir() {\n\t\t\treturn os.MkdirAll(destination, 0755)\n\t\t}\n\t\tif entry.Type()&os.ModeSymlink != 0 {\n\t\t\treturn errors.New(\"staged document tree contains a symbolic link\")\n\t\t}\n\t\treturn filelock.Copy(current, destination)\n\t})\n}\n\nfunc availableObsidianNotebookName(requested string) string {\n\tbase := sanitizeObsidianTitle(requested)\n\texisting := map[string]bool{}\n\tboxes, _ := ListNotebooks()\n\tfor _, box := range boxes {\n\t\texisting[strings.ToLower(box.Name)] = true\n\t}\n\tif !existing[strings.ToLower(base)] {\n\t\treturn base\n\t}\n\tfor index := 2; ; index++ {\n\t\tcandidate := fmt.Sprintf(\"%s (%d)\", base, index)\n\t\tif !existing[strings.ToLower(candidate)] {","sourceCodeStart":2419,"sourceCodeEnd":2455,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/import_obsidian.go#L2419-L2455","documentation":"When materializing the staged temporary document tree into the destination notebook, the copy walk rejects any entry that is a symbolic link with 'staged document tree contains a symbolic link'. This prevents symlink attacks and accidental out-of-tree writes during Obsidian import.","triggerScenarios":"The staged tree directory (or an Obsidian-side file carried into it) contains an entry whose type has `os.ModeSymlink` set at copy time, causing `filepath.WalkDir`'s copy step to return this error.","commonSituations":"The Obsidian vault or temp directory contains symlinks created by Unix tools; an attacker-planted symlink in a shared temp directory; package extraction preserved symlinks.","solutions":["Locate and remove/replace the symlink in the staged tree (resolve it to a real file or drop it)","Re-run the import after cleaning the temp docs directory so staging starts from a clean state","Keep vault assets on the same filesystem and avoid symlinked attachments in Obsidian"],"exampleFix":"// before\nif entry.Type()&os.ModeSymlink != 0 {\n    return errors.New(\"staged document tree contains a symbolic link\")\n}\n// after: copy the symlink target's content instead of failing\nif entry.Type()&os.ModeSymlink != 0 {\n    resolved, rerr := filepath.EvalSymlinks(current)\n    if rerr != nil {\n        return rerr\n    }\n    if !isUnder(resolved, stagingRoot) {\n        return errors.New(\"staged document tree contains a symbolic link\")\n    }\n    return filelock.Copy(resolved, destination)\n}","handlingStrategy":"validation","validationCode":"err := filepath.WalkDir(stagingRoot, func(p string, d fs.DirEntry, err error) error {\n    if err == nil && d.Type()&os.ModeSymlink != 0 {\n        return fmt.Errorf(\"symlink found at %s\", p)\n    }\n    return err\n})","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid symlinked files in the Obsidian vault","Clean the temp docs directory before each import","Extract archives with symlink preservation disabled"],"tags":["security","symlink","file-copy"],"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"}