Skip to main content

Free 30-min security demo  — We'll scan your real code and show live findings, no commitment Book Now

Offensive360
ZeroDays CVE-2024-22051
Critical CVE-2024-22051 CVSS 9.8 CommonMarker Ruby

Integer Overflow in CommonMarker Table Parsing Leads to Heap Corruption

CVE-2024-22051 exploits integer overflow in CommonMarker's GFM table parser, allowing unauthenticated remote attackers to cause heap corruption and achieve RCE via oversized marker rows.

Offensive360 Research Team
Affects: < 0.23.4
Source Code

Overview

CVE-2024-22051 represents a critical integer overflow vulnerability in CommonMarker, the Ruby binding for GitHub’s cmark-gfm Markdown parser, affecting all versions prior to 0.23.4. The vulnerability exists in the GitHub Flavored Markdown (GFM) table parsing logic, specifically when processing table marker rows containing an excessive number of columns. When an attacker crafts a malicious Markdown document with table headers exceeding UINT16_MAX (65,535) columns, an integer overflow occurs during buffer allocation calculations, resulting in heap memory corruption.

This vulnerability carries a CVSS v3.1 score of 9.8 (Critical) and poses a severe risk to any application that parses untrusted Markdown input using affected CommonMarker versions. The attack surface is particularly broad given Markdown’s widespread adoption in documentation systems, content management platforms, collaborative tools, and code repositories. An unauthenticated remote attacker can exploit this vulnerability without authentication, making it trivially exploitable at scale.

Technical Analysis

The vulnerability stems from improper integer handling in the table marker row parsing routine within cmark-gfm. When processing GFM tables, the parser counts the number of delimiter cells (columns) in the table marker row using a 16-bit unsigned integer type. The vulnerable code path allocates heap memory based on this column count without validating that the count fits within safe bounds.

Vulnerable Code Pattern (Conceptual):

// Simplified representation of vulnerable logic
uint16_t column_count = 0;
while (parsing_marker_row) {
    if (is_delimiter_cell()) {
        column_count++;  // Can overflow when input exceeds UINT16_MAX
    }
}

// Integer overflow: column_count wraps to small value
size_t buffer_size = column_count * sizeof(struct table_cell);
void *cells = malloc(buffer_size);  // Allocates insufficient memory

When column_count overflows and wraps around to a small value (e.g., 0 or 1), the subsequent malloc() call allocates a buffer far smaller than what the parser actually writes to. This classic heap buffer overflow allows attackers to:

  1. Corrupt adjacent heap metadata – Overwrite heap allocator structures used to manage memory
  2. Leak sensitive data – Read from memory regions beyond the allocated buffer
  3. Execute arbitrary code – Corrupt function pointers or vtables stored on the heap

The root cause is the use of a 16-bit integer where a 64-bit size_t should have been employed, combined with the absence of bounds checking before the integer is used in size calculations.

Impact

Applications leveraging CommonMarker to parse user-supplied Markdown are vulnerable to complete system compromise. Real-world scenarios include:

  • Documentation platforms (wikis, knowledge bases) accepting user-generated Markdown
  • Issue tracking systems processing Markdown in comments and descriptions
  • Static site generators rendering untrusted Markdown content
  • Collaboration tools with Markdown-based note-taking or messaging
  • Code review platforms parsing Markdown in pull request descriptions

An attacker can achieve remote code execution with the privileges of the application process, potentially compromising data confidentiality, integrity, and availability. Information disclosure is also possible through heap memory corruption techniques that leak sensitive data from adjacent memory regions.

How to Fix It

Immediate Action: Upgrade CommonMarker to version 0.23.4 or later.

For Ruby projects using Bundler:

# Gemfile
gem 'commonmarker', '>= 0.23.4'

Then run:

bundle update commonmarker

For other package managers:

# Using gem directly
gem install commonmarker -v '>= 0.23.4'

# Verify installation
gem list commonmarker

Verification:

require 'commonmarker'

# Confirm patched version
puts CommonMarker::VERSION  # Should be 0.23.4 or higher

The upstream fix in cmark-gfm validates the column count before allocation, ensuring it does not exceed reasonable bounds and changing the integer type to accommodate proper size calculations. The CommonMarker Ruby binding inherits these fixes upon upgrade.

Our Take

This vulnerability exemplifies a classic vulnerability pattern that persists despite decades of security awareness: integer overflow leading to memory corruption. The use of fixed-width integer types for size calculations without explicit validation remains a common source of critical flaws in C and C++ libraries that are wrapped by higher-level languages like Ruby.

Enterprise Perspective: Organizations using CommonMarker should treat this as a zero-day-equivalent threat and prioritize patching immediately. Given the CVSS 9.8 score and unauthenticated attack surface, we recommend:

  1. Inventory all applications using CommonMarker
  2. Test patches in development environments immediately
  3. Deploy to production within 48–72 hours
  4. Monitor logs for any exploitation attempts (excessive table constructs in Markdown input)

This incident underscores why defense-in-depth matters: even with automatic dependency management, organizations should implement input validation, Content Security Policies, and sandboxing of Markdown parsing operations.

Detection with SAST

Static Application Security Testing (SAST) tools can detect this vulnerability through multiple mechanisms:

CWE Coverage: CWE-190 (Integer Overflow), CWE-131 (Incorrect Calculation of Buffer Size)

Detection Patterns:

  • Identification of commonmarker gem dependencies in Gemfile or gemspec with versions < 0.23.4
  • Taint analysis tracking user-controlled Markdown input flowing into CommonMarker.parse() or CommonMarker::Node.parse_gfm() calls
  • Security policy rules flagging known vulnerable dependency versions
  • Code patterns where Markdown parsing results are used without sufficient validation

SAST solutions should flag Markdown parsing operations on untrusted input as potential attack vectors, particularly when combined with dependency version checks that identify affected CommonMarker versions.

References

#integer-overflow #heap-corruption #markdown-parser #remote-code-execution #ruby #commonmarker

Detect this vulnerability class in your codebase

Offensive360 SAST scans your source code for CVE-2024-22051-class vulnerabilities and thousands of other patterns — across 60+ languages.