siyuan-note/siyuan · error
asset path is outside data directory
Error message
asset path is outside data directory
What it means
dataRelativeAssetPath computes the path relative to util.DataDir and rejects any result that escapes the data directory (rel == ".." or starts with "../"). This is a path-traversal guard ensuring downloads only ever target assets inside the workspace data folder.
Solutions
- Ensure the path is under util.DataDir: verify strings.HasPrefix(filepath.Clean(absPath), filepath.Clean(util.DataDir)+string(os.PathSeparator))
- Use GetAssetAbsPath to obtain a legitimate in-workspace absolute path from an asset link
- On Windows, confirm the path is on the same drive/volume as the workspace
Example fix
// before
model.EnsureAssetLocal("/tmp/external/foo.png")
// after
abs := filepath.Join(util.DataDir, filepath.FromSlash("assets/foo.png"))
model.EnsureAssetLocal(abs) Defensive patterns
Strategy: validation
Validate before calling
func insideDataDir(p string) bool {
clean := filepath.Clean(p)
rel, err := filepath.Rel(util.DataDir, clean)
return err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator))
} Try / catch
if err := model.EnsureAssetLocal(p); err != nil && strings.Contains(err.Error(), "outside data directory") {
log.Printf("rejected path outside workspace: %s", p)
} Prevention
- Validate paths are under DataDir before calling download APIs
- Never pass user-supplied or plugin-supplied absolute paths without containment checks
- On Windows, ensure paths are on the same volume as the workspace
When it happens
Trigger: EnsureAssetLocal or EnsureAssetPrefixLocal receives an absolute path outside DataDir, e.g. /etc/passwd, /tmp/other/assets/x.png, or a sibling directory such as /home/user/SiYuan-other/...; also any path where filepath.Rel fails (e.g. different volume roots on Windows, C:\ vs D:\).
Common situations: Caller resolving an asset link against the wrong root; symlinked or joined paths pointing outside the workspace; cross-drive paths on Windows; malicious or buggy plugin passing arbitrary absolute paths.
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
- asset path escapes data directory
- archive entry resolves outside destination
- asset escapes its directory
- asset path escapes data directory
- asset path resolves outside assets directory
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/e7fd662be5b87499.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/asset_download.go:121
case conf.ProviderSiYuan:
if !IsSubscriber() {
return errors.New(Conf.Language(376))
}
case conf.ProviderS3, conf.ProviderWebDAV, conf.ProviderLocal:
if !IsPaidUser() {
return errors.New(Conf.Language(376))
}
}
return nil
}
func dataRelativeAssetPath(absPath string) (string, error) {
if !filepath.IsAbs(absPath) {
return "", fmt.Errorf("asset path must be absolute")
}
rel, err := filepath.Rel(util.DataDir, filepath.Clean(absPath))
if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
return "", fmt.Errorf("asset path is outside data directory")
}
if rel == "." {
return "/", nil
}
return "/" + filepath.ToSlash(rel), nil
}
// EnsureAssetLocal 在调用方完成访问校验后补齐资源,下载内容仍由原有读取流程认证。
func EnsureAssetLocal(absPath string) error {
if _, err := os.Stat(absPath); err == nil {
return nil
} else if !errors.Is(err, os.ErrNotExist) {
return err
}
assetDownloadSourceMu.RLock()
defer assetDownloadSourceMu.RUnlock()
rel, err := dataRelativeAssetPath(absPath)
if err != nil {View on GitHub (pinned to 9f775e8a12)