{"record":{"id":"4c91a9733060ae47","repo":"siyuan-note/siyuan","slug":"export-path-is-outside-export-directory","errorCode":null,"errorMessage":"export path is outside export directory","messagePattern":"export path is outside export directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/encrypted_export.go","lineNumber":219,"sourceCode":"\t\t\t\t\tReleaseEncryptedBoxOperation(boxID)\n\t\t\t\t}\n\t\t\t}()\n\t\t\t_, artifact, resolved = ResolveManagedEncryptedExport(fileName)\n\t\t\tif !resolved {\n\t\t\t\treturn nil, errors.New(\"managed export is unavailable\")\n\t\t\t}\n\t\t\tif _, dekErr := GetDEKIfUnlocked(boxID); dekErr != nil {\n\t\t\t\treturn nil, dekErr\n\t\t\t}\n\t\t\tlease, err = registerMobileExportLease(boxID, artifact, filepath.Base(fileName), \"\")\n\t\t\tif err == nil {\n\t\t\t\trelease = false\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tartifact := filepath.Join(util.TempDir, \"export\", fileName)\n\t\tif !gulu.File.IsSubPath(filepath.Join(util.TempDir, \"export\"), artifact) {\n\t\t\treturn nil, errors.New(\"export path is outside export directory\")\n\t\t}\n\t\treturn registerMobileExportLease(\"\", artifact, filepath.Base(fileName), \"\")\n\t}\n\n\tif !strings.HasPrefix(exportPath, \"assets/\") {\n\t\treturn nil, errors.New(\"unsupported export path\")\n\t}\n\trelativePath, boxID, parseErr := assetPathAndBox(exportPath, \"\")\n\tif parseErr != nil {\n\t\treturn nil, parseErr\n\t}\n\tif boxID == \"\" || !IsEncryptedBox(boxID) {\n\t\tartifact, resolveErr := GetAssetAbsPath(relativePath)\n\t\tif resolveErr != nil {\n\t\t\treturn nil, resolveErr\n\t\t}\n\t\tif ensureErr := EnsureAssetLocal(artifact); ensureErr != nil {\n\t\t\treturn nil, ensureErr","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/encrypted_export.go#L201-L237","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the exportPath and remove any absolute, drive-letter, UNC, or traversal components before prefixing with \"/export/\"","Verify <TempDir>/export itself is not a symlink or junction that breaks gulu.File.IsSubPath containment on your platform","Send the relative artifact name exactly as produced by the export step rather than reconstructing it from client-side state","If you legitimately need files outside <TempDir>/export, use the assets/ path form of the API instead"],"exampleFix":"// before\nreq := \"/export/\" + r.URL.Query().Get(\"file\") // may contain ..\\\\..\\\\secret\n// after\nfile := path.Clean(\"/\" + r.URL.Query().Get(\"file\"))\nfile = strings.TrimPrefix(file, \"/\")\nif strings.Contains(file, \"..\") || filepath.IsAbs(file) { return errors.New(\"bad file\") }\nreq := \"/export/\" + url.PathEscape(file)","handlingStrategy":"validation","validationCode":"function staysInExportDir(p, tempDir) {\n  const art = require(\"path\").join(tempDir, \"export\", p);\n  return art.startsWith(require(\"path\").join(tempDir, \"export\") + require(\"path\").sep);\n}","typeGuard":null,"tryCatchPattern":"try {\n  lease = await acquireExportArtifactLease(p);\n} catch (e) {\n  if (String(e).includes(\"outside export directory\")) {\n    console.error(\"Export path escapes sandbox, rejecting:\", p); // security signal\n  }\n  throw e;\n}","preventionTips":["Reject drive letters, UNC paths, and backslash separators in export filenames before sending","Do not symlink components inside the export temp directory","Reuse the exact relative name the export step returned; never reconstruct it from untrusted input","Audit any code that lets clients influence the export path for traversal input"],"tags":["path-traversal","security","export","validation"],"backgroundTag":"path-traversal-blocked","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}