Oj gem CVE-2026-54502
MEDIUMAttack ChainAIDerived
Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain
-
AccessIdentify endpoint forwarding indent option
-
DeliverySubmit indent value INT_MAX
-
ExploitOj.dump invokes fill_indent
-
Executionmemset overruns stack 'out' buffer
-
PersistRuby worker process crashes
-
ImpactDenial of service
Vulnerability Assessment
| Weakness |
CWE
ASVS 5.0
V15 - Secure Coding and Architecture Stack buffer bounds checking
MITRE ATT&CK
1 technique across 1 tactic: Execution The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up. |
| Exploitation Conditions | Triggering the bug requires the application to call Oj.dump with the :indent option set to an attacker-influenced or extremely large integer (the PoC uses 2_147_483_647); the value must originate from outside the codebase, because no Oj defaults or internal callers pass such a value. Limiting factors: the Oj gem must be loaded (native C extension build), the vulnerable :indent option must be reachable from untrusted input, and exploitation as demonstrated produces a process crash (DoS) rather than confirmed code execution. Default usage of Oj.dump without a developer-supplied extreme indent is not affected. |
| Impact | No CVSS vector (3.1 or 4.0), EPSS score, KEV status, or SSVC decision is provided in the input, so real-world risk must be inferred from the technical detail. The vulnerability requires the application to deliberately pass an extreme :indent value to Oj.dump - a configuration that no realistic application would use - so widespread remote exploitation is unlikely; the practical impact is denial of service via process crash when untrusted input reaches the indent parameter. While CWE-121 stack-overflow conditions can theoretically enable code execution, the ASAN report shows a deterministic 2 GB memset that will trip guard pages immediately, making weaponization beyond DoS difficult to demonstrate. Treat this as a low-to-medium priority hardening fix for gems that expose Oj.dump options to user input; no public exploit identified at time of analysis. |
| Exploit ScenarioDerived | An application accepts a user-supplied JSON formatting preference (for example, a pretty-print toggle that also passes a numeric indent width) and forwards that value into Oj.dump(obj, mode: :compat, indent: user_value). An attacker submits indent: 2147483647, fill_indent issues a multi-gigabyte memset against the 4 KB stack buffer, and the worker process crashes - repeated requests cause sustained denial of service. No publicly available exploit demonstrating code execution is identified at time of analysis. |
Get an e-mail when this CVE is exploited, patched or re-scored. Free account.
Alert meAnalysisAIv1 – Jun 19, 2026
Stack-based buffer overflow in the Oj Ruby JSON gem (versions prior to 3.17.3) allows a developer-controlled large :indent value passed to Oj.dump to overwrite up to 2 GB of stack memory, crashing the Ruby process. The flaw is reachable only when application code forwards an untrusted or extreme indent value into Oj.dump, and no public exploit identified at time of analysis demonstrates code execution beyond denial of service.
RemediationAI
Vendor-released patch: upgrade the oj gem to version 3.17.3 or later (bundle update oj, then redeploy) as published in GHSA-3v45-f3vh-wg7m (https://github.com/ohler55/oj/security/advisories/GHSA-3v45-f3vh-wg7m). If immediate patching is not possible, audit application code for any call site that forwards user-controlled values into Oj.dump's :indent option and clamp the value to a small bound (for example, reject indents greater than 64) before invoking the serializer; this preserves indented output for legitimate values while preventing the overflow, at the cost of one extra validation check per call. Avoid exposing Oj dump options directly to API consumers or configuration files that untrusted parties can influence.
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 high-performance native C extension that serializes Ruby objects to JSON, distributed via RubyGems (pkg:rubygems/oj). The root cause is CWE-121 (Stack-based Buffer Overflow): in ext/oj/dump.h:77, fill_indent computes len = (size_t)(opts->indent * depth) and calls memset on a fixed-size stack buffer 'out' (4,184 bytes) without bounding opts->indent. Because the indent option is taken as a plain Ruby integer and stored in a C int without range validation, INT_MAX (2,147,483,647) survives the size_t cast and the subsequent multiplication by depth, allowing memset to write far past the stack frame allocated in dump() (oj.c:1453).
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:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N
Exploitation reaches Oj.dump via application input (AV:N, PR:N, UI:N) but requires the app to forward :indent unchanged, and demonstrated impact is a process crash only (A:L, C:N, I:N).
Primary rating from Vendor (https://github.com/ohler55/oj).
CVSS VectorVendor: https://github.com/ohler55/oj
Lifecycle Timeline
1DescriptionCVE.org
Summary
Oj.dump is vulnerable to a stack-based buffer overflow when a large :indent value is provided by the developer. fill_indent in dump.h calls memset(indent_str, ' ', (size_t)opts->indent) without validating the size. When opts->indent is set to INT_MAX (2,147,483,647), the (size_t) cast preserves the large value and memset writes 2 GB into the stack-allocated out buffer (4,184 bytes), corrupting the stack and crashing the process.
Version
- Software: oj gem
- Affected: all versions with
ext/oj/dump.h - Latest tested: 3.17.1 (confirmed present)
Details
ext/oj/dump.h, line 77:
static void fill_indent(Out out, int depth) {
if (0 < out->opts->indent) {
size_t len = (size_t)(out->opts->indent * depth);
// ...
memset(out->buf + ..., ' ', len); // len = 2147483647 * depthThe indent option is accepted as a plain Ruby integer and stored as int without range validation. Multiplying by depth can produce a value larger than any stack or heap buffer.
ASAN report:
==69820==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fd1fc201278
WRITE of size 2147483647 at 0x7fd1fc201278 thread T0
#0 memset
#1 fill_indent /ext/oj/dump.h:77
#2 dump_array /ext/oj/dump_compat.c:165
#3 oj_dump_obj_to_json_using_params /ext/oj/dump.c:818
#4 dump_body /ext/oj/oj.c:1429
#5 dump /ext/oj/oj.c:1480
Address is in stack of thread T0 at offset 4728 in frame:
#0 dump /ext/oj/oj.c:1453
[544, 4728) 'out' <== Memory access at offset 4728 overflows this variableReproduce
require "oj"
obj = [0]
Oj.dump(obj, mode: :compat, indent: 2_147_483_647)Workaround
The develop should not use extreme indents and should not offer the option for users to dump Ruby data with unlimited indentation size.
Executive ViewAI
The Oj Ruby JSON gem (versions prior to 3.17.3) is vulnerable to a stack buffer overflow that crashes Ruby processes when exposed to extreme indent parameter values, creating denial-of-service risk for production applications. Exposure is limited to applications that accept untrusted input for the indent parameter, but organizations must urgently identify these vulnerable systems before public exploit code emerges.
No vendor-released patch identified at time of analysis. Interim mitigations: (1) Input validation to restrict indent values to safe positive integers below 256; (2) Code refactoring to prevent untrusted input from reaching indent parameter; (3) Enhanced monitoring and alerting on unexpected Ruby process crashes; (4) Rate limiting on any API endpoints exposing indent control; (5) Process isolation and memory limits on Ruby application containers; (6) Regular code review and scanning for dangerous Oj.dump patterns accepting external input.
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
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.
A stack-based buffer overflow occurs when a program writes more data to a buffer located on the stack than it was allocated to hold.
GHSA-3v45-f3vh-wg7m
NVD
CVE.org
EPSS
Exploit-DB