{"record":{"id":"e364334ae1c7306d","repo":"siyuan-note/siyuan","slug":"local-asset-path-is-not-allowed","errorCode":null,"errorMessage":"local asset path is not allowed","messagePattern":"local asset path is not allowed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/upload.go","lineNumber":203,"sourceCode":"\t\t\treturn\n\t\t}\n\t\tboxID = bt.BoxID\n\t\tdocDirLocalPath := filepath.Join(util.DataDir, boxID, path.Dir(bt.Path))\n\t\tassetsDirPath = getAssetsDir(filepath.Join(util.DataDir, boxID), docDirLocalPath)\n\t}\n\tif !gulu.File.IsExist(assetsDirPath) {\n\t\tif err = os.MkdirAll(assetsDirPath, 0755); err != nil {\n\t\t\treturn\n\t\t}\n\t}\n\n\tfor index, assetAbsPath := range assetAbsPaths {\n\t\tif strings.HasPrefix(strings.ToLower(assetAbsPath), \"file://\") {\n\t\t\tassetAbsPath = util.FileURLToLocalPath(assetAbsPath)\n\t\t}\n\t\tbaseName := filepath.Base(assetAbsPath)\n\t\tif validateHTMLPath && (util.IsSensitivePath(assetAbsPath) || EncryptedRawPathBoxID(assetAbsPath) != \"\") {\n\t\t\trecordAssetUploadFailure(&failedFiles, index, baseName, errors.New(\"local asset path is not allowed\"))\n\t\t\tcontinue\n\t\t}\n\t\tfName := baseName\n\t\tfName = util.FilterUploadFileName(fName)\n\t\text := filepath.Ext(fName)\n\t\tfName = strings.TrimSuffix(fName, ext)\n\t\text = strings.ToLower(ext)\n\t\tfName += ext\n\t\tif gulu.File.IsDir(assetAbsPath) || !isUpload {\n\t\t\tif !strings.HasPrefix(assetAbsPath, \"\\\\\\\\\") {\n\t\t\t\tassetAbsPath = \"file://\" + assetAbsPath\n\t\t\t}\n\t\t\trecordAssetUploadSuccess(succMap, &succFiles, index, baseName, assetAbsPath)\n\t\t\tcontinue\n\t\t}\n\n\t\tfi, statErr := os.Stat(assetAbsPath)\n\t\tif nil != statErr {","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/upload.go#L185-L221","documentation":"When inserting assets originating from HTML (InsertHTMLLocalAssets, validateHTMLPath=true), each local path is screened with util.IsSensitivePath and EncryptedRawPathBoxID. Paths that are sensitive (system dirs, workspace traversal, dotfile-like escapes) or point inside an encrypted notebook's raw storage are rejected per-file with 'local asset path is not allowed' and skipped, protecting against leaking or copying protected/system content.","triggerScenarios":"InsertHTMLLocalAssets with an assetAbsPaths entry that resolves to a sensitive location (e.g. /etc/..., the workspace data dir itself, parent-traversal like a/../..), or to an encrypted notebook's raw path; also file:// URLs whose decoded local path hits these checks.","commonSituations":"Pasting HTML copied from a page that referenced local disk files; web clipper passing absolute file URLs including OS/system directories; attempts to import files from another encrypted notebook's raw storage.","solutions":["Check the path with util.IsSensitivePath and EncryptedRawPathBoxID before the call and exclude rejected files","Copy the file to a neutral temp/user location first and pass that path instead","For encrypted-notebook content, go through the documented export/insert APIs rather than raw paths","Treat the per-file failure as expected behavior: the file appears in failedFiles and the rest of the batch still succeeds","Do not construct file:// URLs pointing at system or notebook-internal locations"],"exampleFix":"// before\nmodel.InsertHTMLLocalAssets(id, []string{\"file:///etc/passwd\"})\n// after\np := \"/etc/passwd\"\nif util.IsSensitivePath(p) || model.EncryptedRawPathBoxID(p) != \"\" {\n    return errors.New(\"skipping disallowed path\")\n}\nmodel.InsertHTMLLocalAssets(id, []string{\"file://\" + p})","handlingStrategy":"validation","validationCode":"for i, p := range paths {\n    if strings.HasPrefix(strings.ToLower(p), \"file://\") { p = util.FileURLToLocalPath(p) }\n    if util.IsSensitivePath(p) || model.EncryptedRawPathBoxID(p) != \"\" {\n        paths = append(paths[:i], paths[i+1:]...) // or skip per-file\n    }\n}","typeGuard":null,"tryCatchPattern":"succ, files, failed, err := model.InsertHTMLLocalAssets(id, paths)\nfor _, f := range failed {\n    if f.Error == \"local asset path is not allowed\" {\n        log.Printf(\"skipped disallowed path at index %d\", f.Index) // expected, not fatal\n    }\n}","preventionTips":["Pre-screen HTML-sourced paths with IsSensitivePath/EncryptedRawPathBoxID before inserting","Copy questionable local files to a neutral temp directory and insert from there","Never build file:// URLs pointing at system directories or other notebooks' raw storage"],"tags":["security","path-validation","asset"],"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"}