Summary
Default configuration does not check authorization of the signer, it only checks the validity of the signature per section 3.2.2 of https://www.w3.org/TR/2008/REC-xmldsig-core-20080610/#sec-CoreValidation. As such, without additional validation steps, the default configuration allows a malicious actor to re-sign an XML document, place the certificate in a <KeyInfo /> element, and pass xml-crypto default validation checks.
Details
Affected xml-crypto versions between versions >= 4.0.0 and < 6.0.0.
xml-crypto trusts by default any certificate provided via digitally signed XML document's <KeyInfo />.
xml-crypto prefers to use any certificate provided via digitally signed XML document's <KeyInfo /> even if library was configured to use specific certificate (publicCert) for signature verification purposes.
Attacker can spoof signature verification by modifying XML document and replacing existing signature with signature generated with malicious private key (created by attacker) and by attaching that private key's certificate to <KeyInfo /> element.
Vulnerability is combination of changes introduced to 4.0.0 at
Changes at PR provided default method to extract certificate from signed XML document.
  
  
    
        
           | 
           SignedXml.getCertFromKeyInfo = function (keyInfo) {  | 
        
        
           | 
             if (keyInfo != null && keyInfo.length > 0) {  | 
        
        
           | 
               const certs = xpath.select(".//*[local-name(.)='X509Certificate']", keyInfo[0]);  | 
        
        
           | 
               if (certs.length > 0) {  | 
        
        
           | 
                 return utils.derToPem(certs[0].textContent.trim(), "CERTIFICATE");  | 
        
        
           | 
               }  | 
        
        
           | 
             }  | 
        
        
           | 
             | 
        
        
           | 
             return null;  | 
        
        
           | 
           };  | 
        
    
   
 
 
  
  
    
        
           | 
           this.getCertFromKeyInfo = SignedXml.getCertFromKeyInfo;  | 
        
    
   
 
 
and changes at PR prefer output of that method to be used as certificate for signature verification even in the case when library is configured to use specific/pre-configured signingCert
  
  
    
        
           | 
           this.getCertFromKeyInfo(this.keyInfo) || this.signingCert || this.signingKey,  | 
        
    
   
 
 
Name of the signingCert was changed later (but prior to 4.0.0 release) to publicCert:
- 78329fb
 
  
  
    
        
           | 
           this.getCertFromKeyInfo(this.keyInfo) || this.publicCert || this.privateKey,  | 
        
    
   
 
 
Issue was fixed to 6.0.0 by disabling implicit usage of default getCertFromKeyInfo implementation:
Possible workarounds for versions 4.x and 5.x:
- Check the certificate extracted via 
getCertFromKeyInfo against trusted certificates before accepting the results of the validation. 
- Set 
xml-crypto's getCertFromKeyInfo to () => undefined forcing xml-crypto to use an explicitly configured publicCert or privateKey for signature verification. 
PoC
#399
Impact
An untrusted certificate can be used to pass a malicious XML payload through an improperly configured installation of xml-crypto.
   
 
Summary
Default configuration does not check authorization of the signer, it only checks the validity of the signature per section 3.2.2 of https://www.w3.org/TR/2008/REC-xmldsig-core-20080610/#sec-CoreValidation. As such, without additional validation steps, the default configuration allows a malicious actor to re-sign an XML document, place the certificate in a
<KeyInfo />element, and passxml-cryptodefault validation checks.Details
Affected
xml-cryptoversions between versions>= 4.0.0and< 6.0.0.xml-cryptotrusts by default any certificate provided via digitally signed XML document's<KeyInfo />.xml-cryptoprefers to use any certificate provided via digitally signed XML document's<KeyInfo />even if library was configured to use specific certificate (publicCert) for signature verification purposes.Attacker can spoof signature verification by modifying XML document and replacing existing signature with signature generated with malicious private key (created by attacker) and by attaching that private key's certificate to
<KeyInfo />element.Vulnerability is combination of changes introduced to
4.0.0atChanges at PR provided default method to extract certificate from signed XML document.
xml-crypto/lib/signed-xml.js
Lines 405 to 414 in c2b83f9
xml-crypto/lib/signed-xml.js
Line 334 in c2b83f9
and changes at PR prefer output of that method to be used as certificate for signature verification even in the case when library is configured to use specific/pre-configured
signingCertxml-crypto/lib/signed-xml.js
Line 507 in c2b83f9
Name of the
signingCertwas changed later (but prior to4.0.0release) topublicCert:xml-crypto/lib/signed-xml.js
Line 507 in 78329fb
Issue was fixed to
6.0.0by disabling implicit usage of defaultgetCertFromKeyInfoimplementation:Possible workarounds for versions 4.x and 5.x:
getCertFromKeyInfoagainst trusted certificates before accepting the results of the validation.xml-crypto'sgetCertFromKeyInfoto() => undefinedforcingxml-cryptoto use an explicitly configuredpublicCertorprivateKeyfor signature verification.PoC
#399
Impact
An untrusted certificate can be used to pass a malicious XML payload through an improperly configured installation of
xml-crypto.