{"record":{"id":"b8044fd5c62160f6","repo":"crowdsecurity/crowdsec","slug":"failed-to-create-gcm-w","errorCode":null,"errorMessage":"failed to create GCM: %w","messagePattern":"failed to create GCM: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/appsec/challenge/crypto.go","lineNumber":129,"sourceCode":"\t}\n\n\tif len(reason) > MaxAllowlistReasonLen {\n\t\treturn \"\", fmt.Errorf(\"%w: %d > %d\", ErrAllowlistReasonSize, len(reason), MaxAllowlistReasonLen)\n\t}\n\n\tkey, err := deriveKey(masterCookieKey)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tblock, err := aes.NewCipher(key)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create cipher: %w\", err)\n\t}\n\n\tgcm, err := cipher.NewGCM(block)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create GCM: %w\", err)\n\t}\n\n\t// Reject an over-limit envelope before marshaling it.\n\tmaxPlaintext := maxCookieLen/4*3 - 1 - gcm.NonceSize() - gcm.Overhead()\n\tif plaintextLen := cookiePlaintextFixedHeaderLen + len(reason) + proto.Size(envelope); plaintextLen > maxPlaintext {\n\t\treturn \"\", fmt.Errorf(\"%w: plaintext=%d > %d\", ErrCookieTooLarge, plaintextLen, maxPlaintext)\n\t}\n\n\tenvelopeBytes, err := proto.Marshal(envelope)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to marshal challenge cookie proto: %w\", err)\n\t}\n\n\tnonce := make([]byte, gcm.NonceSize())\n\tif _, err := rand.Read(nonce); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to generate nonce: %w\", err)\n\t}\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/appsec/challenge/crypto.go#L111-L147","documentation":"sealCookieV0 wraps the AES block in GCM (Galois/Counter Mode) for authenticated encryption. This error means cipher.NewGCM rejected the block; like the cipher-creation error, it should be unreachable with standard Go crypto primitives and a correctly derived AES key — a defensive internal check.","triggerScenarios":"Calling sealCookieV0 when cipher.NewGCM fails on the derived AES block — an internal invariant breach, not a caller-visible condition in supported configurations.","commonSituations":"Effectively never in production with Go's standard crypto/aes + crypto/cipher packages; would indicate a corrupted toolchain, FIPS-mode restriction, or vendored crypto fork.","solutions":["Check the wrapped error for GCM-specific failure text.","Verify the Go toolchain and crypto packages are unmodified (no vendored forks, standard FIPS constraints reviewed).","Rebuild the binary with an unmodified toolchain if a custom crypto build is suspected."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil {\n    return fmt.Errorf(\"cookie sealing failed (gcm): %w\", err)\n}","preventionTips":["Use an unmodified Go toolchain with standard crypto/cipher.","Review FIPS/compliance modes that might restrict GCM instantiation.","Report occurrences upstream; unreachable under normal builds."],"tags":["appsec","crypto","gcm","internal-error"],"backgroundTag":"internal-invariant-violation","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}