siyuan-note/siyuan · error
history path [ ] is not under history directory
Error message
history path [%s] is not under history directory
What it means
validateHistoryPath finally requires the normalized path to sit under util.HistoryDir. Even paths inside the workspace are rejected if the relative path from HistoryDir escapes it (starts with ..), preventing rollback of arbitrary workspace files through the history APIs.
Solutions
- Ensure the path is rooted under the workspace's history directory (history/...)
- Compute the path relative to util.HistoryDir and confirm it does not begin with '..' before calling
- Use the history listing API to enumerate valid entries rather than pointing at arbitrary workspace files
Example fix
// before
rollbackAssetsHistory("data/assets/foo.png") // not under history/
// after
rollbackAssetsHistory("history/20240101000000-update/<boxID>/assets/foo.png") Defensive patterns
Strategy: validation
Validate before calling
const rel = path.relative(historyDir, path.resolve(workspaceDir, p));
if (rel.startsWith('..') || path.isAbsolute(rel)) throw new Error('path must be under history/'); Try / catch
try { await rollbackAssetsHistory(p); } catch (e) { if (String(e).includes('not under history directory')) { p = path.join('history', p); retry(); } else { throw e; } } Prevention
- Root all history API paths at the history directory
- Do not reuse the history rollback API for arbitrary workspace files
- Assert path.prefix === 'history/' in callers before invoking rollback
When it happens
Trigger: Calling a history API with a workspace-internal but non-history path, e.g. data/storage/... or data/notebooks/..., or a path like history/../data/<file>.
Common situations: Confusing data paths with history paths; attempting to restore a file directly from data/ via the history API; misconfigured tooling that prefixes history entries with extra directories.
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 in workspace
- 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/ba18f766b1825196.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/history.go:613
}
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) {
return true
}
rel, err := filepath.Rel(util.HistoryDir, absPath)
if err != nil {
return false
}
parts := strings.SplitN(filepath.ToSlash(rel), "/", 3)View on GitHub (pinned to 9f775e8a12)