Am I affected?

type your elixir version to check

Description

Uncontrolled Recursion vulnerability in the Elixir standard library allows an attacker who controls a list passed to inspect/1, List.to_string/1, or List.to_charlist/1 to exhaust a BEAM node's memory.

Inspect.List's charlist branch in lib/elixir/lib/inspect.ex classifies a list as a charlist using List.ascii_printable?/2, which examines only the first :printable_limit (4096 by default) elements, and then calls IO.chardata_to_string/1 on the whole term. A list whose printable prefix exceeds that limit but which contains a later element that is not a code point (an atom, an out-of-range integer, or an improper tail) is therefore mis-classified, and the conversion raises ArgumentError. That conversion runs inside List.to_string/1, whose rescue clause builds its message by interpolating inspect(list), which re-enters the same branch and raises again. The nested inspection is an argument to raise, so the recursion is not in tail position and every level is retained: the process stack grows monotonically while each cycle re-walks the list, until the process is killed by max_heap_size or, by default, the node runs out of memory. List.to_charlist/1 has the same rescue shape.

Below the printable limit the inner inspect/1 sees the invalid element within its counter and renders the list in ordinary bracket form, so a single ArgumentError is raised and no recursion occurs.

This issue affects elixir: from 1.15.0-rc.0 before 1.18.5, from 1.19.0-rc.0 before 1.19.6, and from 1.20.0-rc.0 before 1.20.4.

Weaknesses & attack patterns

Weakness

CWE-674 · Uncontrolled Recursion in catalog → MITRE ↗

Attack patterns

CAPEC-130 · Excessive Allocation MITRE ↗

Affected — Elixir Repository ↗

1.15.0-rc.0 < 1.18.5 affected
1.19 series 1.19.0-rc.0 < 1.19.6 affected
1.20 series 1.20.0-rc.0 < 1.20.4 affected
every other version: unaffected
cpe cpe:2.3:a:elixir-lang:elixir:*:*:*:*:*:*:*:*
modules · source files · routines
modules 'Elixir.Inspect.List' · 'Elixir.List' · 'Elixir.IO'
source files lib/inspect.ex · lib/list.ex · lib/io.ex
routines 'Elixir.Inspect.List':inspect/2 · 'Elixir.List':to_string/1 · 'Elixir.List':to_charlist/1 · 'Elixir.List':ascii_printable?/2 · 'Elixir.IO':chardata_to_string/1

Affected — GitHub / elixir-lang/elixir Repository ↗

9718f2b and up affected
1eff1ac not affected
5230d73 not affected
a983c8c not affected
0bba588 not affected
every other version: unaffected
cpe cpe:2.3:a:elixir-lang:elixir:*:*:*:*:*:*:*:*
modules · source files · routines
modules 'Elixir.Inspect.List' · 'Elixir.List' · 'Elixir.IO'
source files lib/elixir/lib/inspect.ex · lib/elixir/lib/list.ex · lib/elixir/lib/io.ex
routines 'Elixir.Inspect.List':inspect/2 · 'Elixir.List':to_string/1 · 'Elixir.List':to_charlist/1 · 'Elixir.List':ascii_printable?/2 · 'Elixir.IO':chardata_to_string/1

Workarounds

Install a global inspect function that renders lists as lists rather than inferring charlists, by calling Inspect.Opts.default_inspect_fun/1 with fn term, opts -> Inspect.inspect(term, %{opts | charlists: :as_lists}) end from the application's start callback. This keeps the charlist branch from being entered at all, so the mis-inferred conversion never raises and the error path cannot recurse.

The trade-off is global: charlists then render in bracket form, so ~c"abc" inspects as [97, 98, 99] everywhere in the application, including in logs and error reports.

References

Credits

Thomas Cioppettini / Scalpel Software Inc Reporter
José Valim Remediation developer
Jonatan Männchen / EEF Coordinator

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:N
« All CVEs