{"record":{"id":"0336ef9fbf6429e9","repo":"JuliusBrussee/caveman","slug":"envelope-decode-wrapped-key-w","errorCode":null,"errorMessage":"envelope: decode wrapped key: %w","messagePattern":"envelope: decode wrapped key: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/envelope/envelope.go","lineNumber":142,"sourceCode":"\t\treturn open(ciphertext, meta, nil)\n\t}\n\tif meta.Scheme != schemeV2 {\n\t\treturn nil, fmt.Errorf(\"envelope: unknown scheme %q\", meta.Scheme)\n\t}\n\taad, scopeHash, err := scopeAAD(scope)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif meta.ScopeHash != scopeHash {\n\t\treturn nil, fmt.Errorf(\"envelope: tenant scope mismatch\")\n\t}\n\treturn open(ciphertext, meta, aad)\n}\n\nfunc open(ciphertext []byte, meta Metadata, aad []byte) ([]byte, error) {\n\twrapped, err := base64.StdEncoding.DecodeString(meta.WrappedDataKey)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"envelope: decode wrapped key: %w\", err)\n\t}\n\tdataKey, err := secretbox.DecryptPayloadKey(wrapped)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"envelope: unwrap data key: %w\", err)\n\t}\n\tblock, err := aes.NewCipher(dataKey)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"envelope: aes: %w\", err)\n\t}\n\tgcm, err := cipher.NewGCM(block)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"envelope: gcm: %w\", err)\n\t}\n\tns := gcm.NonceSize()\n\tif len(ciphertext) < ns {\n\t\treturn nil, fmt.Errorf(\"envelope: ciphertext too short\")\n\t}\n\tnonce, ct := ciphertext[:ns], ciphertext[ns:]","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/shared/platform/envelope/envelope.go#L124-L160","documentation":"open() could not base64-decode the WrappedDataKey field from the envelope metadata. The stored metadata is malformed at the key-encoding level (corruption or a non-standard encoding), so the data key cannot be unwrapped and decryption fails closed before any KMS call.","triggerScenarios":"Thrown at shared/platform/envelope/envelope.go:142 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the metadata blob integrity; restore from backup if corrupted","Ensure producers write standard base64 (StdEncoding) wrapped keys"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}