{"record":{"id":"c96d3a08c6169e0d","repo":"siyuan-note/siyuan","slug":"asset-path-s-does-not-match-data-path-s","errorCode":null,"errorMessage":"asset path [%s] does not match data path [%s]","messagePattern":"asset path \\[(.+?)\\] does not match data path \\[(.+?)\\]","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"kernel/server/serve.go","lineNumber":1097,"sourceCode":"\tif err != nil {\n\t\treturn false\n\t}\n\t_, validatedAbsPath, err := model.ResolveDataAssetPath(filepath.ToSlash(dataRelativePath))\n\treturn err == nil && filepath.Clean(validatedAbsPath) == filepath.Clean(assetAbsPath)\n}\n\nfunc resolveAssetRequestPath(cleanPath, boxID, dataPath string) (string, error) {\n\tif dataPath != \"\" {\n\t\tif boxID != \"\" {\n\t\t\treturn \"\", errors.New(\"box and dataPath cannot be used together\")\n\t\t}\n\t\tdataRelativePath, assetAbsPath, err := model.ResolveDataAssetPath(dataPath)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tassetPath, _, ok := model.AssetPathFromDataRelativePath(dataRelativePath)\n\t\tif !ok || assetPath != cleanPath {\n\t\t\treturn \"\", fmt.Errorf(\"asset path [%s] does not match data path [%s]\", cleanPath, dataPath)\n\t\t}\n\t\treturn assetAbsPath, nil\n\t}\n\tif boxID != \"\" {\n\t\treturn model.GetAssetAbsPathInBox(cleanPath, boxID)\n\t}\n\treturn model.GetAssetAbsPath(cleanPath)\n}\n\nfunc serveAssets(ginServer *gin.Engine) {\n\tginServer.POST(\"/upload\", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, model.Upload)\n\n\tginServer.GET(\"/assets/*path\", model.CheckAuth, func(context *gin.Context) {\n\t\trequestPath := context.Param(\"path\")\n\t\tif \"/\" == requestPath || \"\" == requestPath {\n\t\t\t// 禁止访问根目录 Disable HTTP access to the /assets/ path https://github.com/siyuan-note/siyuan/issues/15257\n\t\t\tcontext.Status(http.StatusForbidden)\n\t\t\treturn","sourceCodeStart":1079,"sourceCodeEnd":1115,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/server/serve.go#L1079-L1115","documentation":"When a dataPath is given, resolveAssetRequestPath derives the canonical asset path from it and requires that it matches the `cleanPath` (the URL path being requested). If the derived asset path differs from the requested path — or AssetPathFromDataRelativePath fails — the request is rejected because the URL and the dataPath point at different files.","triggerScenarios":"Requesting an asset URL whose path does not correspond to the `dataPath` parameter, e.g. `/assets/other.png?dataPath=assets/foo.png`, or passing a dataPath that is not a valid asset-relative path.","commonSituations":"Stale cached asset URLs paired with an updated dataPath; typos when constructing the URL programmatically; a dataPath pointing into a different assets folder than the URL path.","solutions":["Ensure the URL path exactly equals the asset path derived from dataPath (e.g. /assets/foo.png with dataPath=assets/foo.png)","Fix the dataPath value so it maps to the requested asset","Drop dataPath and use box-scoped resolution instead if the path is notebook-relative"],"exampleFix":"// before\nfetchPost(\"/assets/wrong-name.png?dataPath=assets/foo.png\")\n// after\nfetchPost(\"/assets/foo.png?dataPath=assets/foo.png\")","handlingStrategy":"validation","validationCode":"const assetPath = \"/assets/\" + dataPath.replace(/^assets\\//, \"\");\nif (cleanPath !== assetPath) throw new Error(\"URL path and dataPath must match\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive the URL path from dataPath with one function, never hand-write both","Regenerate asset URLs when dataPath values change instead of reusing cached URLs"],"tags":["http","api","path-mismatch"],"backgroundTag":"invalid-argument-value","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"}