fix(forms): restore predefined XML entity decoding without re-opening XXE#171
Open
sroussey wants to merge 1 commit into
Open
Conversation
…ities + DOCTYPE strip PR #165 disabled entity processing entirely (processEntities: false) to defang billion-laughs payloads. That also silently corrupted every XML form value carrying one of the five predefined XML entities — e.g. `Mac Accounting Group & CPAs, LLP` was persisting as the literal four-character string `&` instead of the intended `&`. This restores the standard predefined-entity decode (so `&`, `<`, `>`, `"`, `'` round-trip normally) while keeping XXE / billion- laughs defenses in place: - fast-xml-parser's bounded processEntities config caps entity count, expansion depth, total expansions, and expanded length — a filer-declared chain bombs out at the limit instead of expanding geometrically. - A new stripDoctype() pass removes any leading <!DOCTYPE name [...]> block before parsing, so filer-declared entities never reach the parser at all. getParser() now returns a thin wrapper that runs stripDoctype() before parse(), keeping all callsites unchanged.
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.
Summary
PR #165 disabled entity processing entirely (
processEntities: false) to defang billion-laughs payloads. That also silently corrupted every XML form value carrying one of the five predefined XML entities — e.g. a filer name likeMac Accounting Group & CPAs, LLPwas persisting as the literal four-character string&instead of the intended&. Any field containing&,<,>,", or'was affected.This restores the standard predefined-entity decode (so all five round-trip normally) while keeping XXE / billion-laughs defenses in place.
Fix
Two layers of defense replace the heavy-handed
processEntities: false:Bounded
processEntitiesconfig.fast-xml-parser5.8.0+ supports{ enabled, maxEntityCount, maxExpansionDepth, maxExpandedLength, maxTotalExpansions }.A filer-declared chain bombs out at the configured limit instead of expanding geometrically.
DOCTYPE strip. A new
stripDoctype(xml)pass removes any leading<!DOCTYPE name [ ... ]>block before parsing — including the bracketed internal subset where<!ENTITY ...>declarations live — so filer-declared custom entities never reach the parser at all.getParser()now returns a thin wrapper exposingparse(xml)that runsstripDoctype()before delegating to the underlyingXMLParser, so every existing callsite (Form_D, Form_C, Form_1_A, Form_1_K, Form_1_Z, Form_8_K, Form_3/4/5, Form_144, Form_CFPORTAL) picks up the fix without code changes.Test plan
Mac Accounting Group &amp; CPAs, LLPin a Form D<entityName>round-trips through one decode step toMac Accounting Group & CPAs, LLP.<!DOCTYPE foo [ <!ENTITY xxe "PWNED"> ]>is stripped, so&xxe;in the body parses as the literal&xxe;(NOTPWNED).& < > " ') decode to& < > " '.bun test src/sec/forms/— 423 tests pass across 56 files.bun run build— clean.Generated by Claude Code