BBLabs NewsBBLabs News
NewsAll articlesTopics
ES
BBLabs NewsBBLabs News

BBLabs News

Una historia al día. Cero ruido.

Newsletter técnica de ciberseguridad. Una historia al día sobre CVEs críticos, brechas, bug bounty e IA. Filtrado por IA, escrito para humanos.

Producto

  • Hemeroteca
  • Ediciones
  • Temas
  • Glosario
  • RSS
  • Atom
  • JSON Feed

Editorial

  • Acerca de
  • Suscribirse
  • Cuenta
  • English

Legal

  • Privacidad
  • Términos
  • Contacto: team@bblabs.es

Conectar

  • YouTube · @0xGorka
  • Instagram · @bblabs.es
  • Discord BBLabs
  • Discord Bug Bounty ES
19 artículos·5 ediciones·Desde 2026·Hecho en España
© 2026 BBLabs News·Por Gorka El Bochi
BBLabs NewsBBLabs News
NewsAll articlesTopics
ES
Ruby JSON.generate leaks heap memory via null bytes
Back to homeBug Bounty

Ruby JSON.generate leaks heap memory via null bytes

Ruby's JSON.generate leaks arbitrary heap memory when null bytes are passed via JSON::State.space.

  1. Home
  2. ›
  3. Bug Bounty
  4. ›
  5. Ruby JSON.generate leaks heap memory via null bytes
by Gorka El Bochi Morillo
·
2 min read
·May 30, 2026

What happened

Ruby's `JSON::State` class exposes parameters like `space`, `indent`, `object_nl`, and `array_nl` to control generated JSON formatting. When `space` is initialized with null bytes (`"\0" * 1024`), the native C extension implementing the json gem does not sanitize the parameter before writing it as a separator into the output buffer.

The result: `JSON.generate` output includes arbitrary heap (the process's dynamic memory region — where Ruby stores live objects, strings, and internal structures) content. In the published example, the leak exposes real system paths (`mydata/scm/git/ruby/dist/lib/ruby/2.5.0/json/ext.rb`), internal code fragments (`psych/handlers/recorder.rb`, `Gem::Specification.new`), and whatever strings happen to reside in memory at that moment.

Root cause: a classic *C binding* bug. The native code treats `space` as an opaque string and dumps it directly to the buffer with no null byte check and no length validation.

Why it matters

This pattern surfaces across C bindings in multiple dynamic languages: Python, Ruby, Node.js with native addons. The real risk isn't just the visible stack trace — it's what *might* be in heap at request time: session tokens, API keys loaded as strings, in-memory database credentials.

If the endpoint calling `JSON.generate` accepts client-controlled format options (common in APIs offering pretty-print or custom indentation), this becomes a remote memory oracle. An attacker can vary the `\0` offset across multiple requests and reconstruct heap regions systematically.

The attack surface is wider than it looks: serialization libraries (JSON, YAML, MessagePack) with native bindings are all direct candidates for the same vector.

What to do

  • Validate that `space`, `indent`, `object_nl`, and `array_nl` contain no null bytes before they reach the native extension: `raise ArgumentError if opts.values.any? { |v| v.is_a?(String) && v.include?("\0") }`
  • Whitelist allowed values in APIs that accept client-controlled serialization options (e.g., `space` can only be `" "` or `"\t"`).
  • Check your installed json gem version and apply the patch once available.
  • Apply the same audit to all other `JSON::State` parameters — `indent`, `object_nl`, `array_nl` all pass through the same C binding.

The core lesson: C bindings don't inherit the host language runtime's safety guarantees. Every parameter crossing the native boundary needs explicit validation on the Ruby side before the jump — the runtime won't cover you there.

What to do

  • Validate that space, indent, and object_nl contain no null bytes before hitting C extensions
  • Whitelist format values in APIs where clients control serialization options
  • Audit all native bindings in your stack where external input reaches C/C++ code unsanitized

Share this story

Help more people discover BBLabs News.

Ruby JSON.generate leaks heap memory via null bytes
VerticalDownload image
LinkedInXWhatsApp

Interested in Bug Bounty?

Subscribe to this stream and get the most relevant news every day — no spam, no noise.

Subscribe

Related articles

Destacado
Bug Bounty28 may 2026·2 min

TaxJar: org owner could hijack any member's account

TaxJar (Stripe) let an org owner overwrite any member's email address, enabling full account takeover.

  • Test if org owner role can overwrite another member's email field.
  • Chain email change to password reset to prove full account takeover.
  • Audit all identity fields: phone, username, recovery codes — not just email.
Gorka El Bochi Morillo
Leer artículo
Bug Bounty27 may 2026·2 min

Kimwolf DDoS-for-hire botnet operator arrested in Canada

DoJ arrests Canadian operator of Kimwolf, a DDoS-for-hire botnet built as a variant of AISURU.

Leer artículo
Bug Bounty26 may 2026·3 min

Repo jacking on bundler.io: open supply chain attack

Repo jacking on bundler.io let an attacker claim Bundler's orphaned GitHub repo and inject malicious code into any Ruby project referencing it.

Leer artículo

Want to get news like this every day?

Browse all articles
BBLabs NewsBBLabs News

BBLabs News

Una historia al día. Cero ruido.

Newsletter técnica de ciberseguridad. Una historia al día sobre CVEs críticos, brechas, bug bounty e IA. Filtrado por IA, escrito para humanos.

Producto

  • Hemeroteca
  • Ediciones
  • Temas
  • Glosario
  • RSS
  • Atom
  • JSON Feed

Editorial

  • Acerca de
  • Suscribirse
  • Cuenta
  • English

Legal

  • Privacidad
  • Términos
  • Contacto: team@bblabs.es

Conectar

  • YouTube · @0xGorka
  • Instagram · @bblabs.es
  • Discord BBLabs
  • Discord Bug Bounty ES
19 artículos·5 ediciones·Desde 2026·Hecho en España
© 2026 BBLabs News·Por Gorka El Bochi