The vulnerability lies in the improper construction of regular expressions from user-controllable XML entity names. The fast-xml-parser library uses regular expressions to replace XML entities, but it failed to escape special regex characters within the entity names, specifically the dot ('.'). According to the XML specification, a dot is a valid character in an entity name. However, in a regular expression, a dot is a wildcard that matches any character.
An attacker can define a DOCTYPE entity with a name like 'l.'. The parser would then create a regex like /&l.;/g. When this regex is applied to the XML body, it will match not only &l.; but also < because the dot matches the 't'. Since DOCTYPE entities are processed before built-in entities (<, >, etc.), the attacker's entity value replaces the standard entity, effectively bypassing the entity encoding mechanism. This allows for the injection of arbitrary strings, leading to Cross-Site Scripting (XSS) when the parsed output is rendered in an HTML context, or other injection attacks depending on the context where the output is used.
The patches address this by escaping regex metacharacters in the entity name before creating the RegExp object. The analysis of the provided commits confirms this vulnerability and fix in multiple locations across the codebase, specifically in DocTypeReader.js, OrderedObjParser.js, and v6/EntitiesParser.js.