{"id":"CVE-2026-54902","aliases":["CVE-2026-54902","GHSA-m578-w5vf-rfcm"],"related":[],"kind":"vulnerability","state":"published","title":"Oj: Use-After-Free in Oj::Parser SAJ Long Key Callback","summary":"Oj (Optimized JSON) is a JSON parser and Object marshaller packaged as a Ruby gem. Prior to version 3.17.2, is vulnerable to Use-After-Free when in SAJ mode. The Oj::Parser does not protect cached object keys (≥ 35 bytes) from garbage collection, and a Ruby callback that triggers GC inside hash_end can cause the key string to be reclaimed while the C parser still holds a pointer to it. The subsequent access to the freed string VALUE results in a segfault, confirmed by an RIP pointing to address 0x4242 (a canary-style pattern suggesting control over the freed memory's content). This issue has been fixed in version 3.17.2.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Oj (Optimized JSON) is a JSON parser and Object marshaller packaged as a Ruby gem. Prior to version 3.17.2, is vulnerable to Use-After-Free when in SAJ mode. The Oj::Parser does not protect cached object keys (≥ 35 bytes) from garbage collection, and a Ruby callback that triggers GC inside hash_end can cause the key string to be reclaimed while the C parser still holds a pointer to it. The subsequent access to the freed string VALUE results in a segfault, confirmed by an RIP pointing to address 0x4242 (a canary-style pattern suggesting control over the freed memory's content). This issue has been fixed in version 3.17.2.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`Oj::Parser` in SAJ mode does not protect cached object keys (≥ 35 bytes) from garbage collection. A Ruby callback that triggers GC inside `hash_end` can cause the key string to be reclaimed while the C parser still holds a pointer to it. The subsequent access to the freed string VALUE results in a segfault, confirmed by an RIP pointing to address `0x4242` (a canary-style pattern suggesting control over the freed memory's content).\n\n### Version\n\n- **Software**: oj gem\n- **Affected**: all versions with `ext/oj/saj2.c` / `ext/oj/parser.c`\n- **Latest tested**: 3.17.1 (confirmed present)\n\n### Details\n\nShort keys (≤ 34 bytes) are stored inline on the C stack and are safe. Long keys (≥ 35 bytes) are stored as heap-allocated Ruby String objects passed to `rb_funcall` as the `key` argument. Between the key being resolved and the callback completing, a GC triggered inside the callback (e.g. `GC.start`) can collect the key String, leaving a dangling VALUE.\n\nCrash output:\n```\nlong_key_trigger\n[BUG] Segmentation fault at 0x0000000000004242\n    close_object+0x260    /ext/oj/usual.c:405  (calls rb_funcall with freed key)\n    parse+0x11ff          /ext/oj/parser.c:693\n    parser_parse+0x145    /ext/oj/parser.c:1408\n\nRIP: 0x7fd1b46d68b7  RDI: 0x0000000000004242  (freed key VALUE)\nR12: 0x0000000000004242\n```\n\nThe freed VALUE `0x4242` shows the attacker-controlled content of the key string was loaded as a pointer — a classic use-after-free indicator.\n\n### Reproduce\n\n```ruby\nrequire 'oj'\n\nclass H < Oj::Saj\n  def add_value(value, key)\n    GC.start(full_mark: true, immediate_sweep: true) if key == 'x'\n  end\n  def hash_start(key); end\n  def hash_end(key); end\nend\n\np = Oj::Parser.new(:saj)\np.handler = H.new\np.parse('{\"' + 'A' * 35 + '\":{\"x\":1}}')  # long outer key, GC fires on inner key\n```","format":"markdown","source":"ghsa"},{"lang":"es","text":"Oj (Optimized JSON) es un analizador JSON y un serializador de objetos empaquetado como una gema Ruby. Antes de la versión 3.17.2, es vulnerable a uso después de liberación cuando está en modo SAJ. El Oj::Parser no protege las claves de objetos en caché (? 35 bytes) de la recolección de basura, y una devolución de llamada de Ruby que activa la GC dentro de hash_end puede hacer que la cadena de la clave sea reclamada mientras el analizador C aún mantiene un puntero a ella. El acceso subsiguiente al VALOR de la cadena liberada resulta en un segfault, confirmado por un RIP que apunta a la dirección 0x4242 (un patrón tipo canario que sugiere control sobre el contenido de la memoria liberada). Este problema ha sido solucionado en la versión 3.17.2.","source":"nvd"}],"published":"2026-06-19T20:47:28.000Z","modified":"2026-10-25T17:10:00.197Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N","score":6.3,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N","score":6.3,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","rating":"HIGH"}],"cwes":["CWE-416"],"affected":[{"ranges":[{"version":"< 3.17.2","status":"affected"}],"vendor":"ohler55","product":"oj","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.17.3"}],"ecosystem":"RubyGems","package":"oj","purl":"pkg:gem/oj","source":"ghsa"}],"references":[{"url":"https://github.com/ohler55/oj/security/advisories/GHSA-m578-w5vf-rfcm","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/ohler55/oj","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-07-01T12:37:35.388Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-54902","url":"https://www.cve.org/CVERecord?id=CVE-2026-54902","licence":"CVE Terms of Use","modified":"2026-07-01T12:37:40.878Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-m578-w5vf-rfcm","url":"https://github.com/advisories/GHSA-m578-w5vf-rfcm","licence":"CC-BY-4.0","modified":"2026-09-10T03:51:08.981Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-54902","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54902","licence":"Public domain","modified":"2026-10-25T17:10:00.197Z"}],"updatedAt":"2026-11-25T22:59:26.858Z","epss":{"score":0.00499,"percentile":0.44318,"date":"2026-12-02T12:00:21.000Z"}}