siyuan-note/siyuan · error
asset path [ ] is outside assets directory [ ]
Error message
asset path [%s] is outside assets directory [%s]
What it means
assetPathMapKey computes a stable web-style asset key from a filesystem path; if the computed relative path escapes the assets directory ('..', absolute, or '../' prefix), the kernel rejects it as a safety measure. This prevents assets outside the designated assets root from being indexed or addressed via the assets namespace (path traversal).
Solutions
- Ensure assetPath is genuinely inside assetsDirPath (compute filepath.Rel yourself to pre-check)
- Normalize both paths (filepath.Abs / filepath.Clean) before calling; resolve symlinks that escape the assets tree
- Move external assets into the workspace's assets folder so they are addressable
- Fix callers that hard-code absolute paths instead of deriving them from the data assets root
Example fix
// before: path escapes assets dir
key, err := assetPathMapKey('/data/assets', '/data/other/pic.png', false)
// after: keep asset inside assets root
key, err := assetPathMapKey('/data/assets', '/data/assets/pic.png', false) Defensive patterns
Strategy: validation
Validate before calling
import path from 'path';
function isInsideAssets(assetsDir, assetPath) {
const rel = path.relative(assetsDir, assetPath);
return rel !== '' && rel !== '..' && !rel.startsWith('..' + path.sep) && !path.isAbsolute(rel);
} Type guard
const isSafeRel = (rel) => typeof rel === 'string' && rel !== '.' && rel !== '..' && !rel.startsWith('../') && !path.isAbsolute(rel); Try / catch
if (!isInsideAssets(assetsDir, p)) { rejectAsset(p); return; }
try { await buildAssetMap(p) } catch (e) {
if (e.message.includes('is outside assets directory')) logTraversalAttempt(p);
} Prevention
- Resolve symlinks before passing paths into asset APIs
- Always derive asset paths from the data assets root, never from user input
- Normalize (clean/abs) both directory and file paths before comparison
When it happens
Trigger: Calling assetPathMapKey (directly or via the asset listing walks) with an assetPath whose relative path to assetsDirPath is '.', '..', starts with '../', or is absolute — e.g. mismatched assetsDirPath/assetPath roots, symlinks pointing outside the assets tree, or a caller passing an unnormalized path.
Common situations: Custom tooling passing wrong base directory; symlinked asset folders pointing outside the workspace; workspaces moved/migrated with stale absolute paths; plugins or scripts constructing asset paths manually.
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
- asset path does not belong to a notebook
- asset path escapes data directory
- asset path is outside data directory
- asset path is required
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/3cf6837602f87bc2.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/assets.go:2828
return nil
})
if walkErr != nil {
if os.IsNotExist(walkErr) {
return
}
return nil, fmt.Errorf("walk global assets [%s] failed: %w", dataAssetsAbsPath, walkErr)
}
return
}
func assetPathMapKey(assetsDirPath, assetPath string, isDir bool) (ret string, err error) {
relPath, err := filepath.Rel(assetsDirPath, assetPath)
if err != nil {
return
}
relPath = filepath.ToSlash(relPath)
if relPath == "." || relPath == ".." || strings.HasPrefix(relPath, "../") || path.IsAbs(relPath) {
err = fmt.Errorf("asset path [%s] is outside assets directory [%s]", assetPath, assetsDirPath)
return
}
ret = path.Join("assets", relPath)
if isDir {
ret += "/"
}
return
}
// copyBoxAssetsToDataAssets 将笔记本路径下所有(包括子文档)的 assets 复制一份到 data/assets 中。
func copyBoxAssetsToDataAssets(boxID string) error {
boxLocalPath := filepath.Join(util.DataDir, boxID)
return copyAssetsToDataAssets(boxLocalPath)
}
// copyDocAssetsToDataAssets 将文档路径下所有(包括子文档)的 assets 复制一份到 data/assets 中。
func copyDocAssetsToDataAssets(boxID, parentDocPath string) error {View on GitHub (pinned to 9f775e8a12)