{"record":{"id":"603df1b276538284","repo":"siyuan-note/siyuan","slug":"asset-path-is-sensitive-s","errorCode":null,"errorMessage":"asset path is sensitive: %s","messagePattern":"asset path is sensitive: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/tools/asset.go","lineNumber":242,"sourceCode":"\n\t_, succFiles, failedFiles, err := model.InsertLocalAssets(id, fileList, true)\n\tif err != nil {\n\t\treturn CallToolResult{Content: []ContentItem{{Type: \"text\", Text: \"upload assets failed: \" + err.Error()}}, IsError: true}, nil\n\t}\n\treturn newAssetUploadToolResult(succFiles, failedFiles), nil\n}\n\n// validateAssetUploadPaths 将上传路径归一化为绝对路径，并拒绝敏感路径，\n// 防止通过 AI 提示注入诱导上传本地凭据等敏感文件（如 SSH 私钥、云服务凭据）后外泄。\n// 非敏感的工作区外绝对路径仍然允许上传，与 globalCopyFiles 等接受工作区外路径的接口保持一致。\nfunc validateAssetUploadPaths(fileList []string) ([]string, error) {\n\tfor i, f := range fileList {\n\t\tabs, err := filepath.Abs(strings.TrimSpace(f))\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif util.IsSensitivePath(abs) {\n\t\t\treturn nil, fmt.Errorf(\"asset path is sensitive: %s\", abs)\n\t\t}\n\t\tfileList[i] = abs\n\t}\n\treturn fileList, nil\n}\n\nfunc assetUnused(args map[string]any) (CallToolResult, error) {\n\titems := model.UnusedAssets(true)\n\tif len(items) == 0 {\n\t\treturn CallToolResult{Content: []ContentItem{{Type: \"text\", Text: \"no unused assets found\"}}}, nil\n\t}\n\tvar sb strings.Builder\n\tsb.WriteString(fmt.Sprintf(\"Unused assets (%d):\\n\\n\", len(items)))\n\tfor _, item := range items {\n\t\tsb.WriteString(fmt.Sprintf(\"- %s (%s)\\n\", item.Item, item.Name))\n\t}\n\treturn CallToolResult{Content: []ContentItem{{Type: \"text\", Text: sb.String()}}}, nil\n}","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/tools/asset.go#L224-L260","documentation":"validateAssetUploadPaths rejects any asset upload path that util.IsSensitivePath classifies as sensitive (e.g. paths pointing into the workspace's system/configuration directories or other protected locations). The absolute, trimmed path is echoed in the error and the whole upload fails.","triggerScenarios":"assetUpload receives a file list containing a path that, after filepath.Abs, resolves under a sensitive directory — such as workspace conf/, temp/system paths, or other reserved prefixes.","commonSituations":"A client passing workspace configuration or kernel data directories as 'assets'; relative paths that accidentally resolve near protected roots once made absolute; plugins or scripts uploading system files; path traversal attempts.","solutions":["Upload only files located in ordinary user data/asset directories, not workspace system or config paths","Check the path with util.IsSensitivePath(filepath.Abs(path)) client-side before invoking the upload","Remove directory components or traversal segments (..) from supplied paths before calling","Verify the working directory used for relative paths does not cause Abs() to land in a protected tree"],"exampleFix":"// before\nupload(\"conf/appearance.json\")  // sensitive after Abs\n// after\nupload(\"assets/note-attachment.png\")","handlingStrategy":"validation","validationCode":"abs, err := filepath.Abs(strings.TrimSpace(path))\nif err != nil {\n    return err\n}\nif util.IsSensitivePath(abs) {\n    return fmt.Errorf(\"refusing sensitive path: %s\", abs)\n}","typeGuard":null,"tryCatchPattern":"result, err := assetUpload(fileList)\nif err != nil && strings.Contains(err.Error(), \"asset path is sensitive\") {\n    // relocate the file outside protected directories and retry\n}","preventionTips":["Pre-validate every upload path with util.IsSensitivePath after making it absolute","Never upload files from conf/, system temp, or kernel data directories","Reject '..' segments and resolve relative paths against a known-safe base directory"],"tags":["security","path-validation","upload"],"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"}