{"record":{"id":"8d63e1daa9ec2200","repo":"ory/hydra","slug":"cookiex-cannot-bridge-legacy-cookie","errorCode":null,"errorMessage":"cookiex: cannot bridge legacy cookie","messagePattern":"cookiex: cannot bridge legacy cookie","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/cookiex/legacy_securecookie.go","lineNumber":92,"sourceCode":"\tif len(c.legacy.codecs) == 0 {\n\t\treturn zero, errors.WithStack(ErrInvalidCookie)\n\t}\n\tvalues := make(map[any]any)\n\tif err := securecookie.DecodeMulti(name, value, &values, c.legacy.codecs...); err != nil {\n\t\treturn zero, errors.WithStack(ErrInvalidCookie)\n\t}\n\tflat := make(map[string]string, len(values))\n\tfor k, v := range values {\n\t\tkey, keyOK := k.(string)\n\t\tval, valOK := v.(string)\n\t\tif !keyOK || !valOK {\n\t\t\treturn zero, errors.WithStack(ErrInvalidCookie)\n\t\t}\n\t\tflat[key] = val\n\t}\n\tbridge, err := json.Marshal(flat)\n\tif err != nil {\n\t\treturn zero, errors.Wrap(err, \"cookiex: cannot bridge legacy cookie\")\n\t}\n\tvar out T\n\tif err := json.Unmarshal(bridge, &out); err != nil {\n\t\treturn zero, errors.WithStack(ErrInvalidCookie)\n\t}\n\tlegacyDecodes.WithLabelValues(c.purpose).Inc()\n\treturn out, nil\n}\n\n// WithLegacyEncode makes Set seal in the legacy securecookie format under the\n// first legacy key pair, so pods that only understand the legacy format can\n// read freshly minted cookies during a rolling deploy. Requires\n// WithLegacyKeyPairs. This is stage 1 of the rollout; a follow-up removes the\n// option, flipping encoding to the v1 format. JSON null values inside the\n// payload are coerced to empty strings by the bridge; do not use pointer-typed\n// fields while legacy encode is enabled.\nfunc WithLegacyEncode() Option {\n\treturn func(c *config) { c.legacyEncode = true }","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/cookiex/legacy_securecookie.go#L74-L110","documentation":"Returned by openLegacy when marshaling the flattened legacy cookie map to JSON fails during bridging of a legacy securecookie value to the new format. Inputs are map[string]string already validated as strings, so a marshal failure is effectively unreachable and indicates an internal invariant break, not a bad cookie.","triggerScenarios":"Thrown at oryx/cookiex/legacy_securecookie.go:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped json.Marshal error for the exact cause","Verify the flattening loop only inserts string keys and values","Treat as an internal error; do not expose details to the client"],"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"}