{"record":{"id":"0f9109f4f57de5ea","repo":"siyuan-note/siyuan","slug":"history-path-s-is-not-in-workspace","errorCode":null,"errorMessage":"history path [%s] is not in workspace","messagePattern":"history path \\[(.+?)\\] is not in workspace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":606,"sourceCode":"\t\t\treturn\n\t\t}\n\t}\n\n\tif err = filelock.CopyNewtimes(from, to); err != nil {\n\t\tlogging.LogErrorf(\"copy file [%s] to [%s] failed: %s\", from, to, err)\n\t\treturn\n\t}\n\tIncSync()\n\tutil.PushMsg(Conf.Language(102), 3000)\n\treturn nil\n}\n\n// validateHistoryPath 校验历史路径是否位于工作区内且属于历史目录。\n// 拒绝路径穿越攻击（..、绝对路径等）。返回规范化的绝对路径。\nfunc validateHistoryPath(historyPath string) (string, error) {\n\tp := filepath.Join(util.WorkspaceDir, historyPath)\n\tif !gulu.File.IsSubPath(util.WorkspaceDir, p) {\n\t\treturn \"\", fmt.Errorf(\"history path [%s] is not in workspace\", historyPath)\n\t}\n\tif !gulu.File.IsExist(p) {\n\t\treturn \"\", fmt.Errorf(\"history path [%s] not exist\", historyPath)\n\t}\n\trel, err := filepath.Rel(util.HistoryDir, p)\n\tif err != nil || strings.HasPrefix(rel, \"..\") {\n\t\treturn \"\", fmt.Errorf(\"history path [%s] is not under history directory\", historyPath)\n\t}\n\treturn p, nil\n}\n\n// IsEncryptedHistoryPath 判断历史路径是否明确属于加密笔记本。\nfunc IsEncryptedHistoryPath(absPath string) bool {\n\tboxID := ExtractBoxIDFromHistoryPath(absPath)\n\tif boxID == \"\" {\n\t\treturn false\n\t}\n\tif IsEncryptedBox(boxID) {","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L588-L624","documentation":"validateHistoryPath normalizes the caller-supplied history path against the workspace and rejects any path that escapes it, blocking path traversal (.., absolute paths outside the workspace). This error means the given historyPath, after joining with WorkspaceDir, is not a subpath of the workspace.","triggerScenarios":"Calling GetDocHistoryContent, RollbackDocHistory, RollbackAssetsHistory, RollbackNotebookHistory, RollbackAttributeViewHistory, or ResolveDocVersionBoxID with an absolute path outside the workspace or a relative path containing ../ segments.","commonSituations":"Hard-coding history paths from another workspace or machine; building paths by string concatenation that include user input; symlinks or .. segments introduced by external tooling.","solutions":["Pass a path relative to the workspace that stays under the history directory (e.g. history/<op>-<timestamp>/...)","Strip or resolve .. segments and verify the path is inside util.WorkspaceDir before calling the API","Use history listing APIs to obtain valid history paths instead of constructing them manually"],"exampleFix":"// before\nrollbackDocHistory(\"/tmp/other-workspace/history/...\")\n// after\nrollbackDocHistory(\"history/20240101000000-delete-<docID>/<boxID>/<docID>.sy\")","handlingStrategy":"validation","validationCode":"const abs = path.resolve(workspaceDir, p);\nif (!abs.startsWith(path.resolve(workspaceDir) + path.sep)) throw new Error('path escapes workspace');","typeGuard":null,"tryCatchPattern":"try { await rollbackDocHistory(p); } catch (e) { if (String(e).includes('not in workspace')) { p = path.relative(workspaceDir, p); retry(); } else { throw e; } }","preventionTips":["Always pass history paths relative to the workspace root","Sanitize user-supplied paths for .. segments before calling history APIs","Derive paths from history listing APIs rather than external input"],"tags":["history","path-traversal","validation","security"],"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"}