siyuan-note/siyuan · warning

asset path resolves outside notebook assets directory

Error message

asset path resolves outside notebook assets directory

What it means

deferredAssetPathFromFiles performs a second, real-path based containment check: it resolves the asset path, the notebook root, and the data dir via ResolveRealPath (following symlinks), and requires dataDir ⊇ notebookRoot ⊇ assetsRoot ⊇ resolved path. If any resolution fails or the chain of containment breaks — typically because symlinks point outside the notebook — it returns 'asset path resolves outside notebook assets directory'. This ensures deferred asset downloads only touch files actually inside the owning notebook's assets folder.

Solutions

  1. Remove symlinks inside the notebook and keep real files/folders under <notebook>/assets
  2. If sharing media, use SiYuan's own asset referencing or copy files into assets rather than linking
  3. On macOS, avoid /tmp or /var symlinked locations whose real path (/private/var/...) breaks containment checks
  4. Verify with ResolveRealPath that dataDir, notebookRoot and the asset path form a strict containment chain

Example fix

// before
notebook/assets -> /mnt/shared/media
// after
cp -r /mnt/shared/media/* notebook/assets/
rm notebook/assets  # remove the symlink, keep the real directory
Defensive patterns

Strategy: validation

Validate before calling

root, err := model.ResolveRealPath(filepath.Join(util.DataDir, boxID))
resolved, rerr := model.ResolveRealPath(absPath)
if err != nil || rerr != nil || !gulu.File.IsSubPath(root, resolved) {
    return errors.New("asset resolves outside notebook")
}

Try / catch

p, err := model.DeferredAssetPath(link)
if err != nil && strings.Contains(err.Error(), "outside notebook assets directory") {
    relocateAssetIntoNotebook(link) // copy file into assets/, drop symlink
}

Prevention

When it happens

Trigger: deferredAssetPath on an asset whose resolved real path escapes the notebook's assets dir, e.g. assets is a symlink to an external directory, or a nested symlink re-points into another notebook/outside the data dir; exercised by TestDeferredAssetPathRejectsMissingLeafThroughEscapingSymlink.

Common situations: User symlinked a notebook's assets folder to a shared external directory; workspace assembled from linked subdirectories; snapshot restore created symlink layouts that ResolveRealPath normalizes differently across OSes (macOS /private vs /).

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/b359aac2fcc28f04. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/asset_download_read.go:112

			return "", errors.New("asset path escapes data directory")
		}
		if boxID == "" && !IsEncryptedAssetPath(absPath) {
			if _, _, resolveErr := ResolveDataAssetPath(lookupPath); resolveErr != nil {
				return "", resolveErr
			}
		} else {
			resolvedBoxID := boxID
			if resolvedBoxID == "" {
				resolvedBoxID = ExtractBoxIDFromAssetsPath(absPath)
			}
			root, rootErr := ResolveAssetPathWithMissingLeaf(filepath.Join(util.DataDir, resolvedBoxID, "assets"))
			resolved, resolveErr := ResolveAssetPathWithMissingLeaf(absPath)
			notebookRoot, notebookErr := ResolveRealPath(filepath.Join(util.DataDir, resolvedBoxID))
			dataRoot, dataErr := ResolveRealPath(util.DataDir)
			if rootErr != nil || resolveErr != nil || notebookErr != nil || dataErr != nil ||
				!gulu.File.IsSubPath(dataRoot, notebookRoot) ||
				!gulu.File.IsSubPath(notebookRoot, root) || !gulu.File.IsSubPath(root, resolved) {
				return "", errors.New("asset path resolves outside notebook assets directory")
			}
		}
		if lookupPath == relativePath {
			return absPath, nil
		}
		candidates = append(candidates, absPath)
	}
	sort.Strings(candidates)
	if len(candidates) > 0 {
		return candidates[0], nil
	}
	return "", nil
}

// ensureReadableAssetLocal 先检查加密笔记本准入,再下载原始密文;实际读取仍须认证解密。
func ensureReadableAssetLocal(absPath string) error {
	boxID := ExtractBoxIDFromAssetsPath(absPath)
	if boxID != "" && IsEncryptedBox(boxID) && !IsBoxUnlocked(boxID) {

View on GitHub (pinned to 9f775e8a12)