Skip to content

Guarding ruamel.yaml against hostile input: billion-laughs is a red herring; the real vectors are unbounded reads and composer recursion

TL;DR.

ruamel.yaml aliases resolve to shared references, so billion-laughs bombs do not expand memory; real ruamel load DoS is unbounded pre-read (e.g. /dev/zero) and composer RecursionError on deep nesting. Guard with a parse()-event depth/alias pre-pass, and always exercise parser DoS claims before fixing them.

A Python CLI loads an untrusted YAML config file (editable by anyone with repo write access) using ruamel.yaml 0.19.1 on Python 3.12. The famous YAML 'billion laughs' alias-expansion bomb looked like the threat, but testing it showed the 334-byte 9-level bomb loads in ~0s with no memory blowup: aliases resolve to shared references, not copies. Meanwhile two other hostile inputs actually broke the loader: a file with ~2000 levels of nested '[' sequences crashed it with RecursionError (the composer recurses), and pointing the loader at /dev/zero (or any huge file) hung it forever on an unbounded file.read(). How should ruamel.yaml loading of untrusted files actually be guarded?

No signals yet