siyuan-note/siyuan · error

export path is outside export directory

Error message

export path is outside export directory

What it means

For non-managed "/export/..." paths, the artifact is computed as filepath.Join(util.TempDir, "export", fileName) and must remain a strict sub-path of the export temp directory. IsSubPath is a second containment check behind Clean/traversal filtering; if the composed path escapes the export directory (symlinked component, drive-letter/UNC edge case, or residual traversal), the lease is denied to prevent serving arbitrary files.

Solutions

  1. Inspect the exportPath and remove any absolute, drive-letter, UNC, or traversal components before prefixing with "/export/"
  2. Verify <TempDir>/export itself is not a symlink or junction that breaks gulu.File.IsSubPath containment on your platform
  3. Send the relative artifact name exactly as produced by the export step rather than reconstructing it from client-side state
  4. If you legitimately need files outside <TempDir>/export, use the assets/ path form of the API instead

Example fix

// before
req := "/export/" + r.URL.Query().Get("file") // may contain ..\\..\\secret
// after
file := path.Clean("/" + r.URL.Query().Get("file"))
file = strings.TrimPrefix(file, "/")
if strings.Contains(file, "..") || filepath.IsAbs(file) { return errors.New("bad file") }
req := "/export/" + url.PathEscape(file)
Defensive patterns

Strategy: validation

Validate before calling

function staysInExportDir(p, tempDir) {
  const art = require("path").join(tempDir, "export", p);
  return art.startsWith(require("path").join(tempDir, "export") + require("path").sep);
}

Try / catch

try {
  lease = await acquireExportArtifactLease(p);
} catch (e) {
  if (String(e).includes("outside export directory")) {
    console.error("Export path escapes sandbox, rejecting:", p); // security signal
  }
  throw e;
}

Prevention

When it happens

Trigger: AcquireExportArtifactLease with a "/export/" path whose joined artifact is not contained in <TempDir>/export — e.g. path components exploiting platform differences (Windows drive letters, separators), or a name that survives the ".." prefix check but still normalizes outside the base.

Common situations: Cross-platform clients generating paths with \\ or drive letters; symlinked export temp directories confusing containment; crafted URLs from a malicious or buggy client attempting to read files outside the export sandbox.

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/4c91a9733060ae47. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/encrypted_export.go:219

					ReleaseEncryptedBoxOperation(boxID)
				}
			}()
			_, artifact, resolved = ResolveManagedEncryptedExport(fileName)
			if !resolved {
				return nil, errors.New("managed export is unavailable")
			}
			if _, dekErr := GetDEKIfUnlocked(boxID); dekErr != nil {
				return nil, dekErr
			}
			lease, err = registerMobileExportLease(boxID, artifact, filepath.Base(fileName), "")
			if err == nil {
				release = false
			}
			return
		}
		artifact := filepath.Join(util.TempDir, "export", fileName)
		if !gulu.File.IsSubPath(filepath.Join(util.TempDir, "export"), artifact) {
			return nil, errors.New("export path is outside export directory")
		}
		return registerMobileExportLease("", artifact, filepath.Base(fileName), "")
	}

	if !strings.HasPrefix(exportPath, "assets/") {
		return nil, errors.New("unsupported export path")
	}
	relativePath, boxID, parseErr := assetPathAndBox(exportPath, "")
	if parseErr != nil {
		return nil, parseErr
	}
	if boxID == "" || !IsEncryptedBox(boxID) {
		artifact, resolveErr := GetAssetAbsPath(relativePath)
		if resolveErr != nil {
			return nil, resolveErr
		}
		if ensureErr := EnsureAssetLocal(artifact); ensureErr != nil {
			return nil, ensureErr

View on GitHub (pinned to 9f775e8a12)