CVE-2026-54696: Ruby json JSON Generator Heap Buffer Overflow Vulnerability

LOW
Advisory Identifier: GHSA-x2f5-4prf-w687
CVSS 3.7
CWE-122 CWE-787 CWE-131
Published
Advisory Summary

CVE-2026-54696 is a LOW (CVSS 3.7) json generator heap buffer overflow vulnerability (CWE-122: Heap-based Buffer Overflow) affecting Ruby json libraries in the RubyGems ecosystem. The issue involves json generator heap buffer overflow when streaming to an io. Remediation is available by upgrading affected packages to version 2.19.9.

CVE-2026-54696 at a Glance

CVE Identifier CVE-2026-54696
GHSA Identifier GHSA-x2f5-4prf-w687
Severity LOW
CVSS v3.1 Base Score 3.7
CWE Classification CWE-122: Heap-based Buffer Overflow
Affected Product Ruby json
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 3.7

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability Low (A:L)

How to Fix CVE-2026-54696

To remediate this vulnerability, upgrade all affected Ruby json dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

json fixed: 2.19.9
Upgrade json to 2.19.9
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for json

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-54696, inspect your project dependencies for Ruby json:

inspect dependencies for json

Analyze the terminal output to locate any version of Ruby json in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.19.9), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-122: Heap-based Buffer Overflow, where a heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). In Ruby json, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary `JSON.dump(obj, io)` and `JSON::State#generate(obj, io)` can write past the internal JSON generator buffer when a streamed object contains an attacker-controlled string near 16 KB. The issue is a heap out-of-bounds write in the IO-streaming path and is demonstrated as a reliable process crash / denial of service. This was triaged on HackerOne as report #3785370. The issue was confirmed there and I was asked to open it here. ### Details Root cause is in `ext/json/fbuffer/fbuffer.h`, `fbuffer_do_inc_capa()`. On the IO path, the buffer is grown to `FBUFFER_IO_BUFFER_SIZE` (16383), but the early return checks total capacity instead of remaining capacity: ```c if (RB_UNLIKELY(fb->io)) { if (fb->capa < FBUFFER_IO_BUFFER_SIZE) { fbuffer_realloc(fb, FBUFFER_IO_BUFFER_SIZE); } else { fbuffer_flush(fb); } if (RB_LIKELY(requested < fb->capa)) { return; } } ``` If `fb->len` already contains JSON syntax bytes, and a string flush has `16383 - fb->len <= requested < 16383`, this check returns even though there is not enough space left. `fbuffer_append_reserved()` then writes past the buffer: ```c MEMCPY(fb->ptr + fb->len, newstr, char, len); ``` The minimal fix is to compare against the remaining capacity: ```diff - if (RB_LIKELY(requested < fb->capa)) { + if (RB_LIKELY(requested <= fb->capa - fb->len)) { return; } ``` ### PoC ```ruby require "json" require "stringio" io = StringIO.new big = "a" * 16385 big[16382] = '"' # escapable byte near the buffer boundary JSON.dump([big], io) ``` Verified results: ```text Ruby 4.0.5 / bundled json 2.18.0: malloc(): invalid size (unsorted) .../json/common.rb:956: [BUG] Aborted ruby/ruby master c78418b7a0 / json 2.19.8 / ASan: heap-buffer-overflow WRITE of size 16382 fbuffer_append_reserved ext/json/fbuffer/fbuffer.h:145 search_flush ext/json/generator/generator.c:139 convert_UTF8_to_JSON ext/json/generator/generator.c:231 raw_generate_json_string ext/json/generator/generator.c:922 cState_m_generate ext/json/generator/generator.c:1891 ``` Control: the same data through `JSON.dump([big])` without an IO argument returns normally. The bug is specific to the IO-streaming path. ### Impact A remote attacker can trigger a heap out-of-bounds write if they control a string field that an application serializes through `JSON.dump(obj, io)` or `JSON::State#generate(obj, io)`. The demonstrated impact is reliable denial of service. I am not claiming code execution or information disclosure.

CVE-2026-54696 Affected Ruby json Versions

1 component(s)
Fixed Versions:
2.19.9
Product / Package Ecosystem Affected Versions Fixed Version
json
RubyGems
≥ 2.9.0
< 2.19.9
2.19.9

References

Frequently Asked Questions

What is CVE-2026-54696?
CVE-2026-54696 is a security vulnerability in Ruby json involving JSON generator heap buffer overflow when streaming to an IO under CWE-122: Heap-based Buffer Overflow.
Which Ruby json versions are affected?
Affected versions include releases prior to 2.19.9 across affected packages: json.
What version fixes CVE-2026-54696?
Upgrading to 2.19.9 (or the latest patched release for your respective branch) resolves the vulnerability.
Is json affected?
Yes, json is affected in releases prior to 2.19.9. Upgrade your dependency to 2.19.9 or later.
What is the CVSS score of CVE-2026-54696?
CVE-2026-54696 has a CVSS v3.1 base score of 3.7 (LOW) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L.
What CWE is associated with CVE-2026-54696?
CVE-2026-54696 is classified under CWE-122: Heap-based Buffer Overflow (A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().).
How can I check RubyGems dependencies for CVE-2026-54696?
Run the dependency tree command: 'inspect dependencies for json'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-x2f5-4prf-w687",
  "modified" : "2026-07-23T19:48:08Z",
  "published" : "2026-07-23T19:48:08Z",
  "aliases" : [ "CVE-2026-54696" ],
  "summary" : "Ruby json: JSON generator heap buffer overflow when streaming to an IO",
  "details" : "### Summary\n\n`JSON.dump(obj, io)` and `JSON::State#generate(obj, io)` can write past the\ninternal JSON generator buffer when a streamed object contains an\nattacker-controlled string near 16 KB. The issue is a heap out-of-bounds write\nin the IO-streaming path and is demonstrated as a reliable process crash /\ndenial of service.\n\nThis was triaged on HackerOne as report #3785370. The issue was confirmed there\nand I was asked to open it here.\n\n### Details\n\nRoot cause is in `ext/json/fbuffer/fbuffer.h`, `fbuffer_do_inc_capa()`.\n\nOn the IO path, the buffer is grown to `FBUFFER_IO_BUFFER_SIZE` (16383), but the\nearly return checks total capacity instead of remaining capacity:\n\n```c\nif (RB_UNLIKELY(fb->io)) {\n    if (fb->capa < FBUFFER_IO_BUFFER_SIZE) {\n        fbuffer_realloc(fb, FBUFFER_IO_BUFFER_SIZE);\n    } else {\n        fbuffer_flush(fb);\n    }\n\n    if (RB_LIKELY(requested < fb->capa)) {\n        return;\n    }\n}\n```\n\nIf `fb->len` already contains JSON syntax bytes, and a string flush has\n`16383 - fb->len <= requested < 16383`, this check returns even though there is\nnot enough space left. `fbuffer_append_reserved()` then writes past the buffer:\n\n```c\nMEMCPY(fb->ptr + fb->len, newstr, char, len);\n```\n\nThe minimal fix is to compare against the remaining capacity:\n\n```diff\n-        if (RB_LIKELY(requested < fb->capa)) {\n+        if (RB_LIKELY(requested <= fb->capa - fb->len)) {\n             return;\n         }\n```\n\n### PoC\n\n```ruby\nrequire \"json\"\nrequire \"stringio\"\n\nio = StringIO.new\nbig = \"a\" * 16385\nbig[16382] = '\"'          # escapable byte near the buffer boundary\n\nJSON.dump([big], io)\n```\n\nVerified results:\n\n```text\nRuby 4.0.5 / bundled json 2.18.0:\nmalloc(): invalid size (unsorted)\n.../json/common.rb:956: [BUG] Aborted\n\nruby/ruby master c78418b7a0 / json 2.19.8 / ASan:\nheap-buffer-overflow WRITE of size 16382\n  fbuffer_append_reserved  ext/json/fbuffer/fbuffer.h:145\n  search_flush             ext/json/generator/generator.c:139\n  convert_UTF8_to_JSON     ext/json/generator/generator.c:231\n  raw_generate_json_string ext/json/generator/generator.c:922\n  cState_m_generate        ext/json/generator/generator.c:1891\n```\n\nControl: the same data through `JSON.dump([big])` without an IO argument returns\nnormally. The bug is specific to the IO-streaming path.\n\n### Impact\n\nA remote attacker can trigger a heap out-of-bounds write if they control a\nstring field that an application serializes through `JSON.dump(obj, io)` or\n`JSON::State#generate(obj, io)`. The demonstrated impact is reliable denial of\nservice. I am not claiming code execution or information disclosure.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "json"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.9.0"
      }, {
        "fixed" : "2.19.9"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/ruby/json/security/advisories/GHSA-x2f5-4prf-w687"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-54696"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/json/commit/996bac686d64e4e3aaeae03b14a7f9ee9695ebdb"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ruby/json"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/json/releases/tag/v2.19.9"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/json/CVE-2026-54696.yml"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-122", "CWE-131", "CWE-787" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-07-23T19:48:08Z",
    "nvd_published_at" : "2026-06-30T23:17:28Z"
  }
}