Skip to main content

Oj gem CVE-2026-54902

MEDIUM
Use After Free (CWE-416)
2026-06-19 https://github.com/ohler55/oj GHSA-m578-w5vf-rfcm
6.3
CVSS 4.0 · Vendor: https://github.com/ohler55/oj
View

Attack ChainAIDerived

Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain

  1. Access
    Identify endpoint parsing JSON with Oj SAJ
  2. Delivery
    Submit JSON with 35+ byte key
  3. Exploit
    Trigger GC inside hash_end callback
  4. Execution
    Free cached key VALUE
  5. Persist
    Parser dereferences dangling pointer
  6. Impact
    Ruby worker segfaults (DoS)

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

The target application must (1) use Oj::Parser.new(:saj) - not Oj.load DOM mode and not the legacy Oj::Saj API - with a custom handler, (2) parse attacker-controlled JSON, (3) include an object key of 35 bytes or more so the key is heap-allocated rather than stack-inlined, and (4) execute a SAJ callback (notably hash_end, or add_value as in the PoC) that triggers a Ruby garbage collection cycle, either explicitly via GC.start or implicitly via allocations during the callback. No authentication or user interaction beyond submitting the JSON payload is required, but exploitation is limited to deployments matching this specific SAJ-handler configuration; default Oj users are not affected.

Impact

No CVSS vector is supplied by NVD or the vendor, so all severity inference is qualitative. Realistic impact is primarily denial of service against any Ruby process that calls Oj::Parser.new(:saj) on attacker-influenced JSON while using a SAJ handler whose callbacks can cause GC - which in practice means almost any non-trivial Ruby callback, since allocations happen implicitly. The CWE-416 pattern combined with the attacker-controlled 0x4242 pointer value suggests memory corruption / RCE is not theoretically excluded, but no weaponized exploit has been demonstrated and exploitation in CRuby would require defeating ASLR and predicting heap layout, which is significantly harder than in a typical UAF. EPSS and KEV data are not provided; the vulnerability is not listed as actively exploited. Net assessment: a credible DoS bug for any web service that streams untrusted JSON through SAJ, lower realistic priority for services that only use the default Oj.load / document parser, and a 'patch promptly' rather than 'panic' issue.

Exploit ScenarioDerived

An attacker submits a JSON document with an outer object whose key is at least 35 bytes (e.g. 35 'A' characters) and a nested value that causes the application's SAJ callback to allocate enough to trigger a GC cycle inside hash_end; the parser then dereferences the freed key VALUE, segfaulting the Ruby worker. A public proof-of-concept is included in the GHSA advisory demonstrating the crash with an explicit GC.start in the handler, which an attacker can adapt against any web endpoint that streams untrusted JSON through Oj::Parser SAJ.

This Month Plan within 30 days. Why: MEDIUM severity (CVSS 4.0-6.9).
Patch available 0.3% exploitation probability (EPSS)

Get an e-mail when this CVE is exploited, patched or re-scored. Free account.

Alert me

AnalysisAIv1 – Jun 19, 2026

Use-after-free in the Oj Ruby JSON gem's SAJ parser allows an attacker who can influence parsed JSON content and the SAJ callback handler to crash the Ruby process and potentially corrupt memory. Oj::Parser fails to protect heap-allocated cached object keys of 35 bytes or more from garbage collection, so a GC cycle triggered from inside a hash_end callback frees the key while C code still holds a dangling VALUE pointer. No public exploit identified at time of analysis, but a working reproducer is published in the GHSA advisory.

RemediationAI

Vendor-released patch: upgrade the oj gem to 3.17.3 or later (bundle update oj and pin '~> 3.17.3' in the Gemfile), which is the fixed version recorded in the GHSA advisory at https://github.com/ohler55/oj/security/advisories/GHSA-m578-w5vf-rfcm. Where an immediate upgrade is not possible, switch JSON parsing off Oj::Parser SAJ mode by using Oj.load (DOM mode) or the standard library 'json' gem for untrusted input - at the cost of higher memory usage on large documents - or audit SAJ handler callbacks to remove any code paths that can trigger GC (avoid GC.start, large allocations, and require/autoload inside hash_end/add_value), which is fragile because implicit allocations are hard to eliminate. If neither is feasible, reject or size-limit incoming JSON so that no object key can reach 35 bytes; this is a brittle control that breaks legitimate payloads with long keys and should only be a stopgap.

Affected Packages

rubygems oj fix: 3.17.3

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/serializer for Ruby implemented as a C extension (pkg:rubygems/oj). The bug lives in the SAJ (Simple API for JSON) streaming parser implemented in ext/oj/saj2.c and ext/oj/parser.c, with the offending rb_funcall site in ext/oj/usual.c:405 (close_object). Short keys up to 34 bytes are kept inline on the C stack and are unaffected; keys of 35 bytes or longer are materialized as Ruby String objects on the GC-managed heap and passed to user callbacks. Because the parser does not mark or pin that VALUE across the callback, any GC cycle reachable from Ruby code inside hash_end can reclaim the string, leaving the C parser with a freed VALUE that is subsequently dereferenced - the textbook CWE-416 Use-After-Free pattern. The crash artefact (RIP/RDI = 0x4242 matching the attacker-supplied 'A' key bytes) demonstrates that the freed slot's contents are attacker-influenced, which is what makes this more than a pure stability issue.

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

Vendor (https://github.com/ohler55/oj) PRIMARY 6.3 MEDIUM
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
vuln.today AI 5.9 MEDIUM

Remote attacker-controlled JSON reaches a SAJ handler over the network without auth (AV:N/PR:N/UI:N); exploitation needs a long key plus GC inside the callback, so AC:H; demonstrated impact is process crash (A:H), no confirmed C/I.

3.1 AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H
4.0 AV:N/AC:H/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
Red Hat MEDIUM

Primary rating from Vendor (https://github.com/ohler55/oj).

CVSS VectorVendor: https://github.com/ohler55/oj

Attack Vector
Network
Attack Complexity
Low
Attack Requirements
Present
Privileges Required
None
User Interaction
None
Vulnerable system: Confidentiality
None
Vulnerable system: Integrity
None
Vulnerable system: Availability
Low
Subsequent system: Confidentiality
None
Subsequent system: Integrity
None
Subsequent system: Availability
None

Lifecycle Timeline

1
CVSS changed
Jul 01, 2026 - 00:22 NVD
6.3 (MEDIUM)

DescriptionCVE.org

Summary

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).

Version

  • Software: oj gem
  • Affected: all versions with ext/oj/saj2.c / ext/oj/parser.c
  • Latest tested: 3.17.1 (confirmed present)

Details

Short 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.

Crash output:

long_key_trigger
[BUG] Segmentation fault at 0x0000000000004242
    close_object+0x260    /ext/oj/usual.c:405  (calls rb_funcall with freed key)
    parse+0x11ff          /ext/oj/parser.c:693
    parser_parse+0x145    /ext/oj/parser.c:1408

RIP: 0x7fd1b46d68b7  RDI: 0x0000000000004242  (freed key VALUE)
R12: 0x0000000000004242

The freed VALUE 0x4242 shows the attacker-controlled content of the key string was loaded as a pointer - a classic use-after-free indicator.

Reproduce

ruby
require 'oj'

class H < Oj::Saj
  def add_value(value, key)
    GC.start(full_mark: true, immediate_sweep: true) if key == 'x'
  end
  def hash_start(key); end
  def hash_end(key); end
end

p = Oj::Parser.new(:saj)
p.handler = H.new
p.parse('{"' + 'A' * 35 + '":{"x":1}}')
# long outer key, GC fires on inner key

Executive ViewAI

Why It Matters

The Oj Ruby JSON parsing gem contains a use-after-free vulnerability that allows attackers who control JSON input and callback handlers to crash Ruby applications and potentially corrupt memory. Any organization using Oj for JSON parsing faces immediate availability risk and potential data integrity exposure. No vendor patch currently exists, requiring immediate workaround evaluation and architectural controls.

Business Impact: High
Compensating Controls

Implement strict JSON payload validation and size limits; isolate Oj processing in containerized environments with memory limits and automatic restart; deploy application-level monitoring for process crashes with alerting; rate-limit JSON processing endpoints; apply network-layer access controls to JSON-handling services; evaluate switching to alternative Ruby JSON parsers (e.g., json gem, fast_jsonapi) for new implementations; use WAF rules to detect abnormal JSON patterns if endpoints are externally facing.

Threat Intelligence Overview

EPSS Score
0.3%
Top 83% exploitable
Threat Intel
1
1 source
Data Quality
6 sources
Confidence: High
NVD CVE.org EPSS GHSA Vendor GitHub VulDB

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.

SignalValue
Severity MEDIUM
CISA KEV No
Public POC No
EPSS 0.3%
Patch available Yes
Active threat No
Deciding rule
MEDIUM severity (CVSS 4.0-6.9)
What every action level means
Emergency Immediate action required. Criteria: CRITICAL + in CISA KEV (actively exploited) without patch, OR CRITICAL + EPSS > 30% without patch, OR CRITICAL + active threat signals without patch.
Act Now Prioritize within 24-48h. Criteria: in KEV with patch available, OR CRITICAL + public POC, OR HIGH + EPSS > 10%, OR CRITICAL + active threat, OR any CRITICAL severity.
This Week Schedule remediation this week. Criteria: HIGH severity (CVSS 7.0-8.9). Patch within normal change window.
This Month Plan within 30 days. Criteria: MEDIUM severity (CVSS 4.0-6.9), lower exploitation probability. Include in regular patch cycle.
Monitor Track and reassess. Criteria: LOW severity (CVSS 0.1-3.9), minimal exploitation risk. No immediate action needed.

SSVC AssessmentENISA

SSVC Decision· derived
Scheduled
Exploitation· derived
None
System Exposure· derived
Open
Automatable· derived
Yes
Human Impact
High

Priority Score

32
Low Medium High Critical
KEV: 0
EPSS: 0
CVSS: +32
PoC: 0
Weaponized: 0
Threat intel: 0
Gov advisory: 0

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.

Denial of Service attacks render applications or systems unavailable by overwhelming resources or triggering failure conditions.

Affected Products (CPE)CVE.org

pkg:rubygems/oj

Vendor StatusVendor

This site uses cookies essential for authentication and security. No tracking or analytics cookies are used. Privacy Policy