{"record":{"id":"7931b513c4d16cf1","repo":"ory/hydra","slug":"cookiex-cannot-create-aead","errorCode":null,"errorMessage":"cookiex: cannot create AEAD","messagePattern":"cookiex: cannot create AEAD","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/cookiex/cookiex.go","lineNumber":142,"sourceCode":"// aad binds a ciphertext to this codec's purpose and the cookie name, so a\n// sealed value cannot be replayed as a different cookie or in a different\n// context, even under the same key.\nfunc (c *Codec[T]) aad(name string) []byte {\n\treturn []byte(aadPrefix + \"|\" + c.purpose + \"|\" + name)\n}\n\nfunc (c *Codec[T]) seal(name string, value T) (string, error) {\n\tpayload, err := json.Marshal(value)\n\tif err != nil {\n\t\treturn \"\", errors.Wrap(err, \"cookiex: cannot marshal cookie value\")\n\t}\n\tplaintext, err := json.Marshal(envelope{IssuedAt: c.now().Unix(), Values: payload})\n\tif err != nil {\n\t\treturn \"\", errors.Wrap(err, \"cookiex: cannot marshal envelope\")\n\t}\n\ta, err := aead.New(c.keys[0])\n\tif err != nil {\n\t\treturn \"\", errors.Wrap(err, \"cookiex: cannot create AEAD\")\n\t}\n\t// The nonce is prepended to the ciphertext. AEADs that manage the nonce\n\t// internally report a nonce size of zero, so this also covers them.\n\tnonce := make([]byte, a.NonceSize())\n\tif _, err := rand.Read(nonce); err != nil {\n\t\treturn \"\", errors.Wrap(err, \"cookiex: cannot generate nonce\")\n\t}\n\tsealed := a.Seal(nonce, nonce, plaintext, c.aad(name))\n\treturn formatPrefix + base64.RawURLEncoding.EncodeToString(sealed), nil\n}\n\nfunc (c *Codec[T]) open(name, value string) (T, error) {\n\tvar zero T\n\traw, err := base64.RawURLEncoding.DecodeString(strings.TrimPrefix(value, formatPrefix))\n\tif err != nil {\n\t\treturn zero, errors.WithStack(ErrInvalidCookie)\n\t}\n\tfor _, key := range c.keys {","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/cookiex/cookiex.go#L124-L160","documentation":"Returned by Codec.seal when constructing the AEAD cipher from the codec's 32-byte key fails. Keys are already fixed-size arrays derived by HKDF at construction time, so this only fires if the underlying AEAD implementation rejects the key — an environmental/library-level failure, not bad input.","triggerScenarios":"Thrown at oryx/cookiex/cookiex.go:142 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the wrapped error for the cipher-library failure reason","Verify the codec was built via New so keys are correctly HKDF-derived 32-byte arrays","Treat as non-recoverable for this request; signal a server-side error"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}