{"record":{"id":"2936ff25379871dc","repo":"ory/hydra","slug":"cookiex-cannot-generate-nonce","errorCode":null,"errorMessage":"cookiex: cannot generate nonce","messagePattern":"cookiex: cannot generate nonce","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/cookiex/cookiex.go","lineNumber":148,"sourceCode":"\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 {\n\t\ta, err := aead.New(key)\n\t\tif err != nil {\n\t\t\treturn zero, errors.Wrap(err, \"cookiex: cannot create AEAD\")\n\t\t}\n\t\tif len(raw) < a.NonceSize() {\n\t\t\tcontinue","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/cookiex/cookiex.go#L130-L166","documentation":"Returned by Codec.seal when reading from the crypto random source to generate the AEAD nonce fails. A failing system entropy source (CSPRNG) prevents sealing any cookie; the error wraps the underlying rand read error.","triggerScenarios":"Thrown at oryx/cookiex/cookiex.go:148 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check host entropy availability and the wrapped rand error","Retry the Set operation once in case of a transient entropy shortage","Treat persistent failures as a host-level problem requiring investigation"],"exampleFix":null,"handlingStrategy":"retry","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"}