The vulnerability is a classic Signature Wrapping attack due to a parser differential between Ruby's REXML and Nokogiri XML parsers. The ruby-saml library used Nokogiri for cryptographic signature validation but allowed the application to use REXML for extracting data from the SAML response. An attacker could craft a SAML response containing both a validly signed (but ignored) assertion and a malicious, unsigned assertion. The different parsers would produce different document structures, causing the signature validation logic to check the benign assertion while the data extraction logic would read from the malicious one, leading to an authentication bypass.
The patch addresses this by fundamentally changing how the XML document is handled. It introduces a single, secure XML loading mechanism (XMLSecurity::BaseDocument.safe_load_xml) that is used consistently. More importantly, the signature validation process in XMLSecurity::SignedDocument.validate_signature was refactored. The new logic first identifies the exact XML element that the signature covers (the referenced_xml), validates its digest, and then ensures that all subsequent data extractions (via methods like OneLogin::RubySaml::Response.xpath_first_from_signed_assertion) can only 'see' this cryptographically verified part of the document. This prevents the application from ever accessing the malicious, unsigned parts of a wrapped SAML response.