siyuan-note/siyuan · error
history path [ ] is not in workspace
Error message
history path [%s] is not in workspace
What it means
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.
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
Example fix
// before
rollbackDocHistory("/tmp/other-workspace/history/...")
// after
rollbackDocHistory("history/20240101000000-delete-<docID>/<boxID>/<docID>.sy") Defensive patterns
Strategy: validation
Validate before calling
const abs = path.resolve(workspaceDir, p);
if (!abs.startsWith(path.resolve(workspaceDir) + path.sep)) throw new Error('path escapes workspace'); Try / catch
try { await rollbackDocHistory(p); } catch (e) { if (String(e).includes('not in workspace')) { p = path.relative(workspaceDir, p); retry(); } else { throw e; } } Prevention
- 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
When it happens
Trigger: Calling GetDocHistoryContent, RollbackDocHistory, RollbackAssetsHistory, RollbackNotebookHistory, RollbackAttributeViewHistory, or ResolveDocVersionBoxID with an absolute path outside the workspace or a relative path containing ../ segments.
Common situations: 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.
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
- history path [ ] is not under history directory
- asset path escapes data directory
- asset path escapes data directory
- export path is outside export directory
- import path is not sub path of import dir
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/0f9109f4f57de5ea.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/history.go:606
return
}
}
if err = filelock.CopyNewtimes(from, to); err != nil {
logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
return
}
IncSync()
util.PushMsg(Conf.Language(102), 3000)
return nil
}
// validateHistoryPath 校验历史路径是否位于工作区内且属于历史目录。
// 拒绝路径穿越攻击(..、绝对路径等)。返回规范化的绝对路径。
func validateHistoryPath(historyPath string) (string, error) {
p := filepath.Join(util.WorkspaceDir, historyPath)
if !gulu.File.IsSubPath(util.WorkspaceDir, p) {
return "", fmt.Errorf("history path [%s] is not in workspace", historyPath)
}
if !gulu.File.IsExist(p) {
return "", fmt.Errorf("history path [%s] not exist", historyPath)
}
rel, err := filepath.Rel(util.HistoryDir, p)
if err != nil || strings.HasPrefix(rel, "..") {
return "", fmt.Errorf("history path [%s] is not under history directory", historyPath)
}
return p, nil
}
// IsEncryptedHistoryPath 判断历史路径是否明确属于加密笔记本。
func IsEncryptedHistoryPath(absPath string) bool {
boxID := ExtractBoxIDFromHistoryPath(absPath)
if boxID == "" {
return false
}
if IsEncryptedBox(boxID) {View on GitHub (pinned to 9f775e8a12)