The vulnerability lies in the samlify library's handling of template substitution for SAML assertions. The core of the issue is in the replaceTagsByValue function located in src/libsaml.ts. This function was designed to replace placeholders in an XML template with user-provided data.
An analysis of the security patch b37a65ce9959c8f3d85a71d22d82eaaac0ef66cb reveals that the function only escaped values destined for XML attributes, leaving values for element text unescaped. Specifically, the line return quote ? ${quote}${xmlEscape(text)} : text; in the escapeTag helper function demonstrates that xmlEscape was only called if a quote was present, which is indicative of an attribute context. For element text, the raw text was returned.
This flaw could be exploited by an attacker providing a specially crafted value for an attribute like email or name. This value would include malicious XML, such as closing the current AttributeValue and Attribute elements and then opening new ones to grant elevated privileges (e.g., a 'role' attribute with the value 'admin'). When the IdP generates the SAML assertion using createLoginResponse, this malicious XML gets embedded and signed. The Service Provider would then trustingly parse these injected attributes, leading to a privilege escalation.
The identified vulnerable function, SamlLib.replaceTagsByValue, would be the one appearing in a runtime profile during the exploitation of this vulnerability, as it is directly responsible for the insecure substitution.