Oj gem CVE-2026-54897
LOWAttack ChainAIDerived
Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain
-
AccessGain ability to run Ruby in target process
-
DeliveryOpen JSON with Oj::Doc
-
ExploitCall each_child/each_value/each_leaf
-
ExecutionBlock invokes doc.close freeing buffer
-
PersistIterator reads freed cur->next
-
ImpactTrigger crash or memory corruption
Vulnerability Assessment
| Weakness |
CWE
ASVS 5.0
V15 - Secure Coding and Architecture Memory lifecycle management
MITRE ATT&CK
2 techniques across 2 tactics: Execution, Privilege Escalation The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up. |
| Exploitation Conditions | Exploitation requires that the target Ruby process load the Oj gem (versions before 3.17.3) and invoke one of |
| Impact | No CVSS vector is provided by NVD or the vendor, and the issue is not listed in CISA KEV; EPSS data is not supplied. Realistic risk is moderate: triggering the bug requires that the application both iterates an Oj::Doc and yields control to code paths that can call |
| Exploit ScenarioDerived | An application uses |
Get an e-mail when this CVE is exploited, patched or re-scored. Free account.
Alert meAnalysisAIv1 – Jun 19, 2026
Heap use-after-free in the Oj Ruby gem's Oj::Doc iterators (each_value, each_child, each_leaf) allows a Ruby block executed during iteration to free the underlying document buffer via doc.close, after which the native C iterator in ext/oj/fast.c dereferences the freed region. The flaw is reachable from pure Ruby and confirmed by an AddressSanitizer report against version 3.17.1, with no public exploit identified at time of analysis but a clear reproducer published in the GHSA advisory. Applications that parse attacker-influenced JSON with Oj::Doc and pass user-supplied callbacks into these iterators are most at risk.
RemediationAI
Vendor-released patch: upgrade the Oj gem to version 3.17.3 or later (the GHSA advisory at https://github.com/ohler55/oj/security/advisories/GHSA-9ppp-w3g4-fh4q lists < 3.17.2 as vulnerable and 3.17.3 as fixed). Update Gemfile constraints to gem 'oj', '>= 3.17.3' and run bundle update oj, then redeploy any long-running Ruby processes so the patched native extension is loaded. If immediate upgrade is not possible, audit code for uses of Oj::Doc#each_value, each_child, and each_leaf and ensure the yielded block does not call close on the document or any node - wrap iterators so callbacks cannot reach close, or switch parsing paths to Oj.load/Oj.compat_load which use a different code path; the trade-off is reduced streaming performance and potentially higher memory use for large documents.
Affected Packages
Source: OSV (Open Source Vulnerabilities)
Affects your stack
Affects 1 package in rubygems
Checking this CVE against your own stacks and servers is part of the Basic plan and up.
Technical ContextAI · show details
Oj is a widely used high-performance JSON parser for Ruby implemented as a C extension. The vulnerable code lives in ext/oj/fast.c, where iterator functions walk a linked-list of parsed nodes and invoke rb_yield inside the loop. Because rb_yield can run arbitrary Ruby - including Oj::Doc#close, which calls ruby_sized_xfree on the document's backing buffer - the iterator's cur pointer references freed heap memory when control returns from the block. The root cause is the CWE-416 (Use After Free) pattern: re-entrant invocation of native code that mutates lifetimes the caller still depends on. CPE identifier pkg:rubygems/oj covers all distributions of the affected gem.
Know when the next one hits your stack
- Watch products and get an email when something new is published
- Check this CVE against your own stack and servers
- Exploit and PoC references, threat intelligence from 22 sources
No credit card · 7-day full trial
Severity by source
CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N
Requires in-process Ruby code that calls the vulnerable iterator with a close-invoking block (AV:L, PR:L, AC:H); reliable memory corruption is hard, crash impact is high (A:H), info/integrity limited (C:L/I:L).
Primary rating from Vendor (https://github.com/ohler55/oj).
CVSS VectorVendor: https://github.com/ohler55/oj
Lifecycle Timeline
1DescriptionCVE.org
Summary
Oj::Doc iterators (each_value, each_child, each_leaf) are vulnerable to a heap use-after-free. When a Ruby block yielded during iteration calls doc.close or d.close, the document's heap memory is freed while the C iterator is still running. When control returns from the block, the iterator reads from the freed region, producing a use-after-free accessible from pure Ruby.
Version
- Software: oj gem
- Affected: all versions with
ext/oj/fast.c - Latest tested: 3.17.1 (confirmed present)
Details
The iterators in ext/oj/fast.c follow the pattern:
// fast.c:1505 (doc_each_child)
static VALUE doc_each_child(VALUE self, ...) {
...
while (cur != NULL) {
rb_yield(...); // ← Ruby block executes here
cur = cur->next; // ← cur is now freed if block called close()
}
}rb_yield can invoke arbitrary Ruby code, including calling close() on the Doc or any child node, which calls ruby_sized_xfree on the backing buffer. On return, the C code reads cur->next from the freed region. All three iterators are affected.
ASAN report (each_child variant):
==253632==ERROR: AddressSanitizer: heap-use-after-free on address 0x5210000bd080
READ of size 8 at 0x5210000bd080 thread T0
#0 doc_each_child /ext/oj/fast.c:1505
0x5210000bd080 is located 896 bytes inside of 4064-byte region [0x5210000bcd00, 0x5210000bdce0)
freed by thread T0 here:
#0 free
#1 ruby_sized_xfree (libruby-3.3.so.3.3)All three iterators trigger the same freed region (fd shadow bytes):
0x5210000bd080:[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd fdReproduce
require 'oj'
# each_child
Oj::Doc.open('[1,2]') { |doc| doc.each_child { |d| d.close } }
# each_value
Oj::Doc.open('[1,2]') { |doc| doc.each_value { |v| doc.close } }
# each_leaf
Oj::Doc.open('[1,[2]]') { |doc| doc.each_leaf { |d| d.close } }Executive ViewAI
The Oj Ruby gem versions up to 3.17.1 contain a heap use-after-free vulnerability in document iteration that could enable memory corruption in Ruby applications parsing untrusted JSON with user-supplied callbacks. Any organization running web services or API backends using Oj::Doc iterators faces denial-of-service and potential code execution risk, with no vendor patch currently available. The condition-passing external callbacks to Oj::Doc.each_value(), each_child(), or each_leaf()-is realistically exploitable in applications accepting JSON from untrusted sources.
No vendor-released patch identified at time of analysis. Interim mitigations: (1) Prohibit or eliminate user-supplied/external callbacks to Oj::Doc iteration methods; (2) Process only trusted, pre-validated JSON sources with Oj::Doc; (3) Implement strict allowlist-based input validation before Oj parsing; (4) Use alternative JSON libraries (Ruby JSON stdlib, Yajl) for any externally-sourced JSON; (5) Prioritize vendor patch notifications and establish expedited review process for Oj security updates.
Threat Intelligence Overview
How this decision was reached
The engine reads each signal below and applies a fixed list of rules from top to bottom. The first rule that matches sets the recommended action – like a statement, every line is shown.
What every action level means
SSVC AssessmentENISA
Priority Score
Attack Technique
Use-after-free vulnerabilities occur when a program continues to access memory through a pointer after that memory has been deallocated.
Memory corruption occurs when a program writes data beyond the boundaries of allocated memory regions or accesses memory in unintended ways, violating the integrity of the process's address space.
Remote Code Execution represents the critical moment when an attacker successfully runs arbitrary code on a target system without physical access.
GHSA-9ppp-w3g4-fh4q
NVD
CVE.org
EPSS
Exploit-DB