{"record":{"id":"3adcd8ff7cf20c7e","repo":"hyperledger/fabric","slug":"channel-header-not-found-in-the-envelope","errorCode":null,"errorMessage":"channel header not found in the envelope","messagePattern":"channel header not found in the envelope","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccpackage/ccpackage.go","lineNumber":214,"sourceCode":"\t\tendorsements[0] = &peer.Endorsement{Signature: signature, Endorser: endorser}\n\t}\n\n\treturn createSignedCCDepSpec(cdsbytes, instpolicybytes, endorsements)\n}\n\n// SignExistingPackage adds a signature to a signed package.\nfunc SignExistingPackage(env *common.Envelope, owner identity.SignerSerializer) (*common.Envelope, error) {\n\tif owner == nil {\n\t\treturn nil, errors.New(\"owner not provided\")\n\t}\n\n\tch, sdepspec, err := ExtractSignedCCDepSpec(env)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif ch == nil {\n\t\treturn nil, errors.New(\"channel header not found in the envelope\")\n\t}\n\n\tif sdepspec == nil || sdepspec.ChaincodeDeploymentSpec == nil || sdepspec.InstantiationPolicy == nil || sdepspec.OwnerEndorsements == nil {\n\t\treturn nil, errors.New(\"invalid signed deployment spec\")\n\t}\n\n\t// serialize the signing identity\n\tendorser, err := owner.Serialize()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Could not serialize the signing identity: %s\", err)\n\t}\n\n\t// sign the concatenation of cds, instpolicy and the serialized endorser identity with this endorser's key\n\tsignature, err := owner.Sign(append(sdepspec.ChaincodeDeploymentSpec, append(sdepspec.InstantiationPolicy, endorser...)...))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Could not sign the ccpackage, err %s\", err)\n\t}\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccpackage/ccpackage.go#L196-L232","documentation":"SignExistingPackage calls ExtractSignedCCDepSpec to unpack the envelope; even when extraction succeeds, the channel header can be absent (e.g. the envelope payload was not a proper SignedChaincodeDeploymentSpec transaction). This error signals that the envelope contains no ChannelHeader, so the package cannot be attributed to a channel.","triggerScenarios":"Passing a common.Envelope that was not produced by OwnerCreateSignedCCDepSpec/CreateSignedCCDepSpec — e.g. a hand-built envelope, an envelope from a different transaction type, or an envelope whose payload/header was stripped.","commonSituations":"Reading packages from files that were concatenated or truncated; passing a plain (unsigned) ChaincodeDeploymentSpec envelope to SignExistingPackage; mixing envelope formats across Fabric versions.","solutions":["Ensure the envelope comes from ccpackage.OwnerCreateSignedCCDepSpec or CreateSignedCCDepSpecForInstall, not a hand-assembled envelope","Call ExtractSignedCCDepSpec yourself first and inspect the returned header before re-signing","Verify the payload is a *peer.SignedChaincodeDeploymentSpec wrapped with a valid common.Header containing ChannelHeader"],"exampleFix":"// before\nenv, err := ccpackage.SignExistingPackage(badEnv, signer)\n// after\nch, sdepspec, err := ccpackage.ExtractSignedCCDepSpec(env)\nif err != nil || ch == nil { return errors.New(\"envelope is not a signed CDS package\") }\nenv, err = ccpackage.SignExistingPackage(env, signer)","handlingStrategy":"validation","validationCode":"ch, sdepspec, err := ccpackage.ExtractSignedCCDepSpec(env)\nif err != nil || ch == nil {\n    return errors.New(\"envelope is not a signed CDS package\")\n}\nenv, err = ccpackage.SignExistingPackage(env, owner)","typeGuard":"func isSignedCDSEnvelope(env *common.Envelope) bool {\n    ch, _, err := ccpackage.ExtractSignedCCDepSpec(env)\n    return err == nil && ch != nil\n}","tryCatchPattern":"env, err := ccpackage.SignExistingPackage(env, owner)\nif err != nil {\n    if strings.Contains(err.Error(), \"channel header not found\") {\n        return fmt.Errorf(\"envelope was not produced by ccpackage; regenerate it: %w\", err)\n    }\n    return err\n}","preventionTips":["Only pass envelopes produced by ccpackage helpers","Do not hand-assemble envelopes for signed CDS packages","Keep package files intact; avoid manual edits"],"tags":["hyperledger-fabric","envelope","malformed-input","chaincode-package"],"backgroundTag":"malformed-envelope","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}