siyuan-note/siyuan · error
invalid export path
Error message
invalid export path
What it means
AcquireExportArtifactLease validates any path under the "/export/" prefix before issuing a mobile export artifact lease. After URL-decoding and filepath.Clean, if the remaining path is ".", starts with "..", or is absolute, it cannot name a safe relative artifact inside the export temp directory, so the lease is refused. This is a defensive check against path traversal and malformed export URLs.
Solutions
- Check the exportPath passed to AcquireExportArtifactLease: after the "/export/" prefix it must be a non-empty, relative, non-traversal path (no leading "/", no ".." segments)
- URL-encode filename segments once with url.PathEscape when building the path; do not pass raw or double-encoded user input
- Use filepath.Rel or strip the known base directory server-side instead of trusting client-provided relative paths
- Log the exact rejected exportPath and confirm it is the intended artifact name, not a whole URL or an absolute temp path
Example fix
// before
lease, err := model.AcquireExportArtifactLease("/export/" + userPath)
// after
userPath = url.PathEscape(filepath.ToSlash(filepath.Clean(userPath)))
if strings.HasPrefix(userPath, "..") || filepath.IsAbs(userPath) {
return errors.New("refusing to request unsafe export path")
}
lease, err := model.AcquireExportArtifactLease("/export/" + userPath) Defensive patterns
Strategy: validation
Validate before calling
function isSafeExportPath(p) {
if (!p.startsWith("/export/")) return false;
const rest = decodeURIComponent(p.slice("/export/".length));
return rest !== "." && !rest.startsWith("..") && !require("path").isAbsolute(rest);
} Type guard
function hasSafeRelativeName(p) {
return typeof p === "string" && p.length > 0 &&
!p.split("/").some(seg => seg === ".." || seg === ".");
} Try / catch
try {
lease = await acquireExportArtifactLease(p);
} catch (e) {
if (String(e).includes("invalid export path")) {
throw new Error(`Refusing malformed export path: ${p}`); // do not retry
}
throw e;
} Prevention
- Always URL-escape each path segment once with encodeURIComponent/PathEscape when building export paths
- Never splice user-supplied filenames directly onto "/export/"
- Validate with a shared helper (clean + reject '..'/absolute) on both client and server sides
- Treat this error as a programming bug, not a transient failure — do not auto-retry
When it happens
Trigger: Call AcquireExportArtifactLease (directly or via materializeExportArtifact / AcquireMobileExportLease) with a path like "/export/..", "/export/.", "/export/%2e%2e%2fetc", "/export//..", or an absolute path surviving Clean such as "/export/C:\\foo" or a URL-decoded leading-slash segment.
Common situations: Hand-built export URLs with unescaped or double-encoded segments; clients concatenating a user-supplied filename onto "/export/"; stale bookmarks/plugins referencing removed or renamed export temp files; mobile clients passing a full server URL instead of just the export sub-path.
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
- export path is outside export directory
- asset path escapes data directory
- asset path escapes data directory
- export path is outside export directory
- history path [ ] is not in workspace
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/6f2821c8e352456f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/encrypted_export.go:186
// normalExportTempName 避免普通导出使用加密导出的第一层归属目录,保留归档内部的原始名称。
func normalExportTempName(name string) string {
parts := strings.SplitN(filepath.ToSlash(filepath.Clean(name)), "/", 2)
if ast.IsNodeIDPattern(parts[0]) {
parts[0] = "export-" + parts[0]
}
return filepath.FromSlash(strings.Join(parts, "/"))
}
// AcquireExportArtifactLease 为导出产物取得覆盖整个复制过程的生命周期租约。
func AcquireExportArtifactLease(exportPath string) (lease *ExportArtifactLease, err error) {
if after, ok := strings.CutPrefix(exportPath, "/export/"); ok {
fileName, decodeErr := url.PathUnescape(after)
if decodeErr != nil {
return nil, decodeErr
}
fileName = filepath.Clean(fileName)
if fileName == "." || strings.HasPrefix(fileName, "..") || filepath.IsAbs(fileName) {
return nil, errors.New("invalid export path")
}
if IsManagedEncryptedExportPath(fileName) {
boxID, artifact, resolved := ResolveManagedEncryptedExport(fileName)
if !resolved {
return nil, errors.New("managed export is unavailable")
}
if err = AcquireEncryptedBoxOperation(boxID); err != nil {
return nil, err
}
HoldBoxReadLock(boxID)
release := true
defer func() {
if release {
ReleaseBoxReadLock(boxID)
ReleaseEncryptedBoxOperation(boxID)
}
}()
_, artifact, resolved = ResolveManagedEncryptedExport(fileName)View on GitHub (pinned to 9f775e8a12)