Skip to main content

Oj Ruby Gem CVE-2026-54500

MEDIUM
Out-of-bounds Read (CWE-125)
2026-06-19 https://github.com/ohler55/oj
5.3
CVSS 3.1 · Vendor: https://github.com/ohler55/oj
View

Attack ChainAIDerived

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

  1. Access
    Submit crafted JSON with 254+ byte key
  2. Delivery
    Trigger long-key branch in form_attr()
  3. Exploit
    rb_intern3 reads uninitialized stack buffer buf
  4. Execution
    EncodingError raised containing raw stack bytes
  5. Persist
    Application returns error details to caller
  6. Impact
    Attacker extracts leaked stack memory

Vulnerability Assessment

Weakness
CWE
ASVS 5.0
V15 - Secure Coding and Architecture Bounds checking, read limits
MITRE ATT&CK

1 technique across 1 tactic: Collection

The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up.

Exploitation Conditions

Exploitation requires all of the following: (1) the application explicitly calls Oj.load with mode: :object - this is a non-default mode passed intentionally by the developer, not the Oj default; (2) the attacker can supply or influence the JSON string being parsed; (3) the parsed JSON contains at least one key of 254 bytes or longer to enter the vulnerable code branch (keys of 253 bytes or fewer are not affected); and (4) the application surfaces the resulting Symbol or EncodingError back to the attacker, either directly in a response body or via an accessible log or side channel. Exploitation is limited to information disclosure - there is no code execution, write primitive, or availability impact. The CVSS PR:N metric reflects that no authentication to the target application is required to submit JSON, but the :object mode precondition means correctly configured applications that follow Oj's own safety guidance are not vulnerable.

Impact

The CVSS 3.1 vector AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N yields a score of 5.3 (Medium), which is consistent with the vulnerability mechanics: network delivery is trivial and no authentication is required to send JSON, but impact is bounded to low confidentiality with no integrity or availability effect. Several preconditions substantially constrain real-world risk. First, the application must explicitly invoke Oj.load with mode: :object - a non-default mode that Oj's own documentation already flags as unsafe for untrusted input. Second, the attacker cannot control which stack bytes are returned; only that some uninitialized memory is read. Third, the leaked data only reaches an attacker if the application reflects the resulting Symbol or EncodingError back to the caller (e.g., in a debug response or error body). The vulnerability is not listed in CISA KEV and no EPSS score was provided in the input data, so exploitation probability is inferred from preconditions rather than empirical exploitation telemetry. However, a working proof-of-concept is publicly documented in GHSA-fm7p-mprw-wjm9, which lowers the exploitation bar for attackers targeting applications that meet the preconditions. Overall, this is a genuine medium-priority issue for applications processing untrusted JSON in :object mode, and a low-priority issue for those that do not.

Exploit ScenarioDerived

An attacker sends an HTTP POST request to a web API endpoint that accepts JSON and internally calls Oj.load(body, mode: :object), embedding a crafted JSON object with a 300-byte key such as {"^o":"Object","<300 A chars>":1}. The Oj parser triggers the vulnerable form_attr() branch, rb_intern3 reads approximately 301 bytes of uninitialized stack memory, and the Ruby runtime raises an EncodingError whose message contains those raw bytes. If the application returns error details in its HTTP response (common in development or misconfigured production environments), the attacker receives roughly 1,500 bytes of stack contents that may include residual cryptographic keys, session tokens, or other sensitive values previously written to the stack frame. A proof-of-concept reproducing this exact outcome is published in the GitHub Security Advisory.

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

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

Alert me

AnalysisAIv1 – Jun 19, 2026

Stack memory disclosure in the Oj RubyGem (all versions before 3.17.3) allows remote unauthenticated callers to recover uninitialized process stack contents by supplying a JSON object with keys of 254 bytes or longer to Oj.load in :object mode. The root cause is a copy-paste defect in ext/oj/intern.c where form_attr() allocates and fills a correct heap buffer b but then erroneously passes the uninitialized 256-byte stack buffer buf to rb_intern3(), causing leaked bytes to surface in the returned Symbol or an EncodingError message. A proof-of-concept is publicly available in the GHSA advisory; no confirmed active exploitation (CISA KEV) has been identified at time of analysis.

RemediationAI

Upgrade Oj to version 3.17.3 or later, which corrects form_attr() in intern.c to pass the correctly populated heap buffer b to rb_intern3() - a one-character fix mirroring the earlier repair in usual.c. The fix is confirmed by the maintainer and documented at https://github.com/ohler55/oj/security/advisories/GHSA-fm7p-mprw-wjm9. If an immediate gem upgrade is not feasible, the most targeted compensating control is to replace mode: :object with :strict or :compat in all Oj.load calls that process untrusted input; note this changes deserialization behavior for callers relying on Ruby-object reconstruction. A secondary control is input validation that rejects JSON payloads containing keys of 254 bytes or more before they reach Oj.load, though this is fragile if not applied consistently at every entry point. Do not rely on error suppression alone as a mitigation, as the uninitialized read still occurs even if the EncodingError is rescued.

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 ('Optimized JSON') is a high-performance C-extension JSON parser for Ruby distributed as pkg:rubygems/oj. The vulnerable code resides in ext/oj/intern.c within form_attr(), which interns attribute names (as Ruby Symbols) during :object-mode parsing. For keys of 253 bytes or fewer, the function uses a local 256-byte stack buffer buf safely. When a key reaches 254 bytes (triggering the sizeof(buf) - 2 <= len branch), the function correctly heap-allocates a buffer b, populates it with the attribute name, but then calls rb_intern3(buf, len + 1, oj_utf8_encoding) - reading from the uninitialized stack buffer rather than b. For keys of 256 bytes or more, the read also extends past the end of buf, constituting a classic out-of-bounds read (CWE-125). This identical defect had been previously corrected in ext/oj/usual.c; intern.c contained a duplicated copy of form_attr that was missed in the earlier fix cycle. The interned bytes can surface to callers via the Symbol value or, when the stack bytes fail UTF-8 validation, via the text of the EncodingError exception.

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 5.3 MEDIUM
AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
vuln.today AI 5.3 MEDIUM

Network delivery of arbitrary JSON requires no authentication; impact is limited to low confidentiality (uncontrolled stack bytes); no integrity or availability effect.

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

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

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

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
None
Scope
Unchanged
Confidentiality
Low
Integrity
None
Availability
None

DescriptionCVE.org

Summary

Oj.load in :object mode reads uninitialized stack memory (and, for long keys, reads out of bounds) when parsing a JSON object whose key is 254 bytes or longer. The interned bytes can surface to the caller, disclosing process stack memory.

Details

In ext/oj/intern.c, form_attr() handles the long-key path by allocating a heap buffer b, populating it with the attribute name, and then freeing it - but it passed the uninitialized stack buffer buf (not b) to rb_intern3():

c
static VALUE form_attr(const char *str, size_t len) {
    char buf[256];
    if (sizeof(buf) - 2 <= len) {        // long-key path (len >= 254)
        char *b = OJ_R_ALLOC_N(char, len + 2);
        // ... b is filled correctly ...
        id = rb_intern3(buf, len + 1, oj_utf8_encoding);   // BUG: reads `buf`
        OJ_R_FREE(b);
        return id;
    }
    // ...
}

rb_intern3 therefore reads len + 1 bytes of uninitialized stack memory. When the key length is >= 256, it also reads out of bounds past the 256-byte buf (CWE-125). The resulting bytes are interned and can reach the caller via the produced Symbol or via the EncodingError message raised on invalid UTF-8, leaking process stack contents.

This is the same defect previously fixed in ext/oj/usual.c; intern.c held a duplicated copy of form_attr that was missed.

Proof of Concept

ruby
require 'oj'
key  = "A" * 300
json = %Q[{"^o":"Object","#{key}":1}]
Oj.load(json, mode: :object)

On affected versions this raises an EncodingError whose message contains ~1500 bytes of uninitialized stack memory (not the supplied "A"s). The leaked byte count varies between runs with the identical payload (e.g. 1491 vs 1516 bytes), confirming the content is uninitialized memory rather than fixed data.

Impact

Information disclosure of process stack memory to a caller that parses untrusted JSON with Oj.load(..., mode: :object). For keys >= 256 bytes it is also an out-of-bounds read (CWE-125).

Severity is bounded by several preconditions: it requires :object mode (which is already discouraged for untrusted input), the leaked bytes are uncontrolled (the attacker cannot choose what is disclosed), and the data only reaches an attacker if the application surfaces the resulting Symbol or EncodingError back to them. Scored CVSS 5.3 (Medium) on that basis.

Patches

Fixed in 3.17.3: form_attr() now passes b to rb_intern3 (a one-character change mirroring the earlier usual.c fix). Verified on the fixed build: the same payload returns cleanly with no leak across repeated runs.

Credit

Reported by Zac Wang (@7a6163).

Threat Intelligence Overview

EPSS Score
0.2%
Top 90% exploitable
Data Quality
5 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 MEDIUM
CISA KEV No
Public POC No
EPSS 0.2%
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· derived
Medium

Priority Score

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

Attack Technique

A buffer overflow occurs when a program writes more data to a memory buffer than it was allocated to hold, causing the excess data to spill into adjacent memory regions.

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

Vendor StatusVendor

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