Am I affected?

type your mdex version to check

Description

Memory Allocation with Excessive Size Value vulnerability in leandrocp mdex allows an unauthenticated attacker to cause a denial of service through unbounded memory allocation.

comrak_nif::lumis_adapter::LumisAdapter::parse_highlight_lines in native/comrak_nif/src/lumis_adapter.rs eagerly expands a user-controlled inclusive line range from a fenced code block's highlight_lines decorator into a Vec<usize>, pushing one element per integer in the range with no upper bound on the range size. An attacker who can supply Markdown that an application renders with MDEx.to_html/2 (for example a comment, chat message, or wiki page) can embed a code block whose info string is rust highlight_lines="1-100000000", forcing the native adapter to allocate roughly 8 bytes per line in the range.

A payload that differs by only a few bytes can therefore allocate hundreds of megabytes, and a sufficiently large range (for example 1-2000000000) exhausts host memory and aborts the BEAM, denying service to every user of the rendering process. The per-line write loop additionally tests membership with a linear scan over the same vector, degrading rendering to a quadratic cost even for ranges that do not immediately exhaust memory.

The vulnerable native code originally shipped inside mdex (in native/comrak_nif/src/lumis_adapter.rs) and was later extracted into the separate mdex_native package (native/mdex_native_nif/src/lumis_adapter.rs), where it remains unpatched.

This issue affects mdex from 0.11.0 before 0.12.3, and mdex_native from 0.1.0 before 0.2.3.

Weaknesses & attack patterns

Weakness

CWE-789 · Memory Allocation with Excessive Size Value in catalog → MITRE ↗

Attack patterns

CAPEC-130 · Excessive Allocation MITRE ↗

Affected — Hex / mdex Hex.pm ↗ Repository ↗

0.11.0 < 0.12.3 affected
every other version: unaffected
default status unaffected
cpe cpe:2.3:a:leandrocp:mdex:*:*:*:*:*:*:*:*
modules · source files · routines
modules 'Elixir.MDEx' · comrak_nif
source files native/comrak_nif/src/lumis_adapter.rs
routines comrak_nif::lumis_adapter::LumisAdapter::parse_highlight_lines · 'Elixir.MDEx':to_html/2

Affected — GitHub / leandrocp/mdex Repository ↗

a840761 < 6ed94d9 affected
every other version: unaffected
default status unaffected
cpe cpe:2.3:a:leandrocp:mdex:*:*:*:*:*:*:*:*
modules · source files · routines
modules 'Elixir.MDEx' · comrak_nif
source files native/comrak_nif/src/lumis_adapter.rs
routines comrak_nif::lumis_adapter::LumisAdapter::parse_highlight_lines · 'Elixir.MDEx':to_html/2

Affected — Hex / mdex_native Hex.pm ↗ Repository ↗

0.1.0 < 0.2.3 affected
every other version: unaffected
default status unaffected
cpe cpe:2.3:a:leandrocp:mdex_native:*:*:*:*:*:*:*:*
modules · source files · routines
modules 'Elixir.MDExNative.Comrak' · mdex_native_nif
source files native/mdex_native_nif/src/lumis_adapter.rs
routines mdex_native_nif::lumis_adapter::LumisAdapter::parse_highlight_lines · 'Elixir.MDExNative.Native':document_to_html_with_options/2 · 'Elixir.MDExNative.Comrak':document_to_html/2

Affected — GitHub / leandrocp/mdex_native Repository ↗

956528c < 798a363 affected
every other version: unaffected
default status unaffected
cpe cpe:2.3:a:leandrocp:mdex_native:*:*:*:*:*:*:*:*
modules · source files · routines
modules 'Elixir.MDExNative.Comrak' · mdex_native_nif
source files native/mdex_native_nif/src/lumis_adapter.rs
routines mdex_native_nif::lumis_adapter::LumisAdapter::parse_highlight_lines · 'Elixir.MDExNative.Native':document_to_html_with_options/2 · 'Elixir.MDExNative.Comrak':document_to_html/2

Workarounds

Do not enable code-block decorators: leave the github_pre_lang and full_info_string render options unset, or avoid configuring an inline syntax-highlight formatter, so that highlight_lines specifications are never parsed.

Configurations

Exploitation requires the application to enable code-block decorators. Decorators are active only when the render options github_pre_lang and full_info_string are both set and an inline syntax-highlight formatter (for example {:html_inline, ...}) is configured. Applications that render Markdown with the default options do not parse highlight_lines specifications and are not affected.

References

Credits

Peter Ullrich Finder
Leandro Pereira Remediation developer
Jonatan Männchen / EEF Analyst

CVSS breakdown

CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:H
« All CVEs