{"record":{"id":"dcb5d4cdc77b5b79","repo":"siyuan-note/siyuan","slug":"invalid-encrypted-asset-original-name","errorCode":null,"errorMessage":"invalid encrypted asset original name","messagePattern":"invalid encrypted asset original name","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":2348,"sourceCode":"\tif err := json.Unmarshal(data, metadata); err != nil {\n\t\treturn nil, err\n\t}\n\tvar version struct {\n\t\tSpec        json.RawMessage `json:\"spec\"`\n\t\tContainerID json.RawMessage `json:\"containerID\"`\n\t}\n\tif err := json.Unmarshal(data, &version); err != nil {\n\t\treturn nil, err\n\t}\n\t// 仅认证元数据同时缺少两个版本字段时按旧容器读取，显式空值或不完整的新格式不能降级。\n\tif len(version.Spec) == 0 && len(version.ContainerID) == 0 {\n\t\tmetadata.Spec = encryptedAssetLegacySpec\n\t} else if metadata.Spec != encryptedAssetSpec || len(metadata.ContainerID) != encryptedAssetContainerIDSize {\n\t\treturn nil, errors.New(\"unsupported encrypted asset container version\")\n\t}\n\tif metadata.OriginalName == \"\" || metadata.OriginalName == \".\" ||\n\t\tfilepath.Base(metadata.OriginalName) != metadata.OriginalName || strings.ContainsAny(metadata.OriginalName, `/\\`) {\n\t\treturn nil, errors.New(\"invalid encrypted asset original name\")\n\t}\n\tif metadata.Size < 0 {\n\t\treturn nil, errors.New(\"invalid encrypted asset content metadata\")\n\t}\n\tchunks := uint64(metadata.Size) / encryptedAssetChunkSize\n\tif metadata.Size%encryptedAssetChunkSize != 0 || metadata.Size == 0 {\n\t\tchunks++\n\t}\n\tif metadata.Chunks != chunks {\n\t\treturn nil, errors.New(\"invalid encrypted asset chunk count\")\n\t}\n\treturn metadata, nil\n}\n\n// DecryptAssetWithName 解密资源内容并返回原始名称。\nfunc DecryptAssetWithName(boxID, diskName string, dek, ciphertext []byte) (plaintext []byte, originalName string, err error) {\n\tvar output bytes.Buffer\n\toriginalName, err = DecryptAssetToWriter(boxID, diskName, dek, bytes.NewReader(ciphertext), &output)","sourceCodeStart":2330,"sourceCodeEnd":2366,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L2330-L2366","documentation":"The decrypted metadata's OriginalName must be a clean, non-empty base name: not empty or '.', equal to filepath.Base of itself, and containing no '/' or '\\' separators. This error means the authenticated metadata contains an unsafe or malformed original file name, which the kernel refuses to use for writing assets to disk (path-traversal defense).","triggerScenarios":"Decrypting an asset whose metadata OriginalName contains path separators or '..'-style components; metadata crafted/tampered with (though AAD/GCM auth makes silent tampering unlikely); a producer that stored a full path instead of a base name.","commonSituations":"A third-party or older tool encrypted assets storing absolute paths as original names; manually patched metadata; importing containers produced outside the official kernel.","solutions":["Re-encrypt the asset with EncryptAsset passing only filepath.Base(originalName)","If you hold raw metadata, sanitize the name (strip directories) before encryption: originalName = filepath.Base(originalName)","Treat this as a rejected container from an untrusted producer; do not attempt to bypass the check"],"exampleFix":"// before\nenc, err := model.EncryptAsset(box, disk, userProvidedPath, data)\n// after\nbase := filepath.Base(userProvidedPath)\nif base == \".\" || base == \"\" || strings.ContainsAny(base, `/\\\\`) {\n    return errors.New(\"invalid asset name\")\n}\nenc, err := model.EncryptAsset(box, disk, base, data)","handlingStrategy":"validation","validationCode":"func safeAssetName(name string) bool {\n    base := filepath.Base(name)\n    return base != \"\" && base != \".\" && base == name && !strings.ContainsAny(name, `/\\\\`)\n}","typeGuard":null,"tryCatchPattern":"plain, name, err := model.DecryptAssetWithName(box, disk, dek, data)\nif err != nil && strings.Contains(err.Error(), \"invalid encrypted asset original name\") {\n    return fmt.Errorf(\"rejecting container with unsafe embedded name: %w\", err)\n}","preventionTips":["Always pass filepath.Base(originalName) to EncryptAsset, never a user-supplied full path","Reject asset names containing path separators at ingestion time, before encryption","Treat containers failing this check as untrusted input; never fall back to writing the embedded name to disk"],"tags":["encryption","path-traversal","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"}