Reject alias-bomb YAML front matter before parsing#26
Merged
Conversation
YAML front matter is parsed with Yaml::parse(), which resolves anchors and aliases. A few hundred bytes of aliased YAML (a "billion laughs" bomb) expands exponentially: parsing stays cheap, but ParserOutput serializes the result into the parser cache, materializing the full expansion and exhausting memory uncatchably -- reachable by any editor, since Markdown is the default content model everywhere. Add a FrontMatterGuard that inspects only the raw block (never a parsed structure, so its cost stays bounded by the input size) and rejects front matter that uses more than a handful of anchor/alias markers or exceeds a generous size ceiling. Rejected front matter is treated as absent and stripped from the body. Legitimate metadata -- including & and * inside plain scalars and the occasional single-anchor reuse -- still parses unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #26 +/- ##
============================================
+ Coverage 82.37% 82.76% +0.39%
- Complexity 314 323 +9
============================================
Files 33 34 +1
Lines 834 853 +19
============================================
+ Hits 687 706 +19
Misses 147 147 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Authored with Claude Code (
claude-opus-4-8 (max)), directed by Jeroen. Closes a denial-of-service vector in YAML front matter:Yaml::parse()resolves anchors and aliases, so a few hundred bytes of aliased YAML (a "billion laughs" bomb) expands exponentially — parsing stays cheap, butParserOutputserializes the result into the parser cache, materializing the full expansion and exhausting memory uncatchably (reachable by any editor, since Markdown is the default content model everywhere). AFrontMatterGuardinspects only the raw block (never a parsed structure, so its cost stays bounded by input size) and rejects front matter that uses more than a handful of anchor/alias markers — including aliases pinned against a quoted key's colon in JSON-style flow mappings — or exceeds a generous size ceiling; the exact rejected block is stripped so nothing leaks into the body. Legitimate metadata (including&/*inside plain scalars and the occasional single-anchor reuse) still parses unchanged.