Skip to main content

Oj gem CVE-2026-54898

LOW
Use After Free (CWE-416)
2026-06-19 https://github.com/ohler55/oj GHSA-q2gm-54r6-8fwm
2.1
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. Recon
    Load malicious or buggy SAJ handler in Ruby process
  2. Delivery
    Invoke Oj::Parser#parse with attacker-influenced JSON
  3. Exploit
    Callback (hash_start) calls String#replace with larger payload
  4. Install
    Ruby frees original string buffer via ruby_sized_xfree
  5. C2
    C parser dereferences dangling const byte* at parser.c:607
  6. Execute
    Read freed heap memory, corrupt parser state
  7. Impact
    Information disclosure or process crash

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 application must instantiate Oj::Parser with the :saj or :saj2 mode and assign a handler whose callbacks (hash_start, hash_end, array_start, array_end, or add_value) mutate the exact String object passed to parser.parse(json) in a way that grows it beyond its embedded capacity, forcing Ruby to reallocate and free the original buffer; mutation via String#replace, <<, gsub!, or concat with a larger payload is sufficient. Exploitation is limited by the fact that the attacker must control the handler code (typically application-level Ruby), not just the JSON input - supplying malicious JSON to an application that uses Oj.load or a non-mutating SAJ handler does not trigger the bug. Versions of the oj gem below 3.17.2 containing ext/oj/parser.c are affected; the fixed release is 3.17.3.

Impact

No CVSS vector was published in the input, so risk must be reasoned from the technical detail and CWE. Realistically this is a low-to-moderate severity issue: exploitation requires the attacker to control the SAJ/SAJ2 handler object passed to Oj::Parser, which is application code, not raw JSON input - an attacker who can only supply JSON to a parser using a benign application-defined handler cannot trigger the UAF. KEV status is not listed, EPSS is unpublished, and no public exploit identified at time of analysis, though the GHSA advisory contains a complete reproducer that demonstrates use-after-free reliably under ASAN. The tag list ('Memory Corruption, Information Disclosure, Use After Free') overstates the practical attack surface because the realistic trigger is malicious or buggy in-process handler code, not remote untrusted JSON; treat as a correctness/hardening fix rather than an exposed RCE primitive unless a downstream library exposes callback registration to untrusted users.

Exploit ScenarioDerived

A developer writes (or imports) a SAJ-style handler whose hash_start callback resizes the original JSON string - for example, a logging wrapper that calls @json.replace(redact(@json)) - and when Oj::Parser#parse is invoked the C parser continues reading from the freed buffer at parser.c:607, producing memory corruption that can leak adjacent heap contents into subsequently parsed values or crash the Ruby worker. The published GHSA reproducer (Mutator class calling @json.replace('x' * 1_000_000) inside hash_start) demonstrates the use-after-free deterministically under AddressSanitizer.

Monitor Track and reassess. Why: LOW severity (CVSS 0.1-3.9).
Patch available 0.1% exploitation probability (EPSS)

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

Alert me

AnalysisAIv1 – Jun 19, 2026

Heap use-after-free in the Oj Ruby JSON parser allows malicious SAJ/SAJ2 callback handlers to dereference freed memory by mutating the input JSON string mid-parse, potentially leading to memory disclosure or arbitrary code execution within the Ruby process. The flaw affects the oj gem at versions below 3.17.2 and is triggered when a callback such as hash_start invokes String#replace with a larger payload, causing Ruby to reallocate the backing buffer that the C parser still references. No public exploit identified at time of analysis, but a fully working reproducer is published in the upstream GHSA advisory.

RemediationAI

Vendor-released patch: upgrade the oj gem to version 3.17.3 or later (the GHSA advisory specifies 'fixed in: 3.17.3'); update Gemfile 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. Until upgrade is possible, the only meaningful workaround is to audit and constrain SAJ/SAJ2 handler classes so callbacks (hash_start, hash_end, array_start, array_end, add_value) never invoke mutating methods on the JSON string being parsed - specifically forbid String#replace, <<, gsub!, concat or any operation that can resize the source buffer; alternatively, route untrusted JSON through Oj.load or Oj::Doc instead of Oj::Parser with custom SAJ handlers. Refer to https://github.com/ohler55/oj/security/advisories/GHSA-q2gm-54r6-8fwm for upstream details; note that the handler-audit workaround relies on developer discipline and offers no runtime enforcement.

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 high-performance JSON parser written as a Ruby C extension (pkg:rubygems/oj), widely used as a drop-in replacement for the standard JSON library and by frameworks such as Rails for serialization. The vulnerability lives in ext/oj/parser.c where parser_parse extracts a raw const byte* via StringValuePtr() from the Ruby String object and passes it directly into the parse() loop at line 607. This pattern violates Ruby's C-API contract because user-controlled SAJ/SAJ2 callbacks executed mid-parse can mutate the same String (via String#replace, <<, gsub!, etc.), causing ruby_sized_xfree to release the embedded buffer and leaving the C parser with a dangling pointer - a textbook CWE-416 (Use-After-Free) caused by failing to re-fetch the buffer pointer after re-entering Ruby code.

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 2.1 LOW
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
vuln.today AI 3.9 LOW

Exploitation requires in-process control of the SAJ handler code (PR:H, AV:L) and a race-like buffer-realloc condition (AC:H); UAF yields limited memory disclosure and possible crash, no scope change.

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

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

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

Attack Vector
Local
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
2.1 (LOW)

DescriptionCVE.org

Summary

Oj::Parser#parse is vulnerable to a heap use-after-free when a SAJ/SAJ2 callback mutates the input JSON string during parsing. The C engine holds a raw const byte * pointer into the Ruby string's internal buffer. If a callback (e.g. hash_start) resizes the string - for example by calling String#replace with a longer value - Ruby reallocates the string buffer and frees the old one. The C parser's pointer is left dangling; the next character read at parser.c:607 is a use-after-free.

Version

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

Details

ext/oj/parser.c, parser_parse → parse:

c
static VALUE parser_parse(VALUE self, VALUE json) {
    const byte *ptr = (const byte *)StringValuePtr(json);  // raw pointer into Ruby string
    // ...
    parse(p, ptr);   // ptr used throughout; any realloc frees the backing buffer
}
c
// parser.c:607
static void parse(ojParser p, const byte *json) {
    const byte *b = json;
    // ...
    for (; '\0' != *b; b++) {   // ← UAF: reads freed memory after callback resizes json

Ruby's String#replace (or <<, gsub!, etc.) can trigger a reallocation of the string's internal buffer if the new content is larger than the embedded capacity, freeing the old buffer that ptr still points to.

ASAN report:

==372273==ERROR: AddressSanitizer: heap-use-after-free on address 0x51900008ed81
READ of size 1 at 0x51900008ed81 thread T0
    #0 parse          /ext/oj/parser.c:607
    #1 parser_parse   /ext/oj/parser.c:1408
0x51900008ed81 is located 1 bytes inside of 1023-byte region [0x51900008ed80, 0x51900008f17f)
freed by thread T0 here:
    #0 free
    #1 ruby_sized_xfree  (libruby-3.3.so.3.3)
Shadow bytes: [fd]fd fd fd fd fd ...  (entire region freed)

Reproduce

ruby
require 'oj'

class Mutator
  def initialize(json) = (@json = json; @done = false)

  def hash_start(key)
    return if @done; @done = true
    @json.replace('x' * 1_000_000)
# triggers String realloc, frees original buffer
  end

  def hash_end(key); end
  def array_start(key); end
  def array_end(key); end
  def add_value(value, key); end
end

json = '{"a":1,"pad":"' + ('A' * 1000) + '","z":2}'
parser = Oj::Parser.new(:saj)
parser.handler = Mutator.new(json)
parser.parse(json)

Executive ViewAI

Why It Matters

The Oj Ruby JSON parser gem (versions below 3.17.2) contains a vulnerability enabling arbitrary code execution within Ruby applications processing JSON data, with no public exploit identified at time of analysis. This impacts any organization using Oj to parse user input or external JSON feeds; a published proof-of-concept demonstrates the vulnerability is readily exploitable. Immediate inventory and interim security controls are required.

Business Impact: High
Compensating Controls

No vendor-released patch identified at time of analysis. Interim mitigations: disable SAJ/SAJ2 callbacks in Oj configuration; implement strict JSON input validation and schema validation; restrict Oj parsing to trusted JSON sources only; monitor application behavior for heap corruption or unexpected process termination; implement network-based detection rules for exploitation attempts; establish incident response procedures for potential system compromise.

Threat Intelligence Overview

EPSS Score
0.1%
Top 98% exploitable
Threat Intel
1
1 source
Data Quality
4 sources
Confidence: Medium

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 LOW
CISA KEV No
Public POC No
EPSS 0.1%
Patch available Yes
Active threat No
Deciding rule
LOW severity (CVSS 0.1-3.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
Small
Automatable· derived
No
Human Impact
High

Priority Score

10
Low Medium High Critical
KEV: 0
EPSS: 0
CVSS: +10
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.

Information disclosure occurs when an application unintentionally exposes sensitive data that aids attackers in reconnaissance or directly compromises security.

Affected Products (CPE)CVE.org

pkg:rubygems/oj

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