KeyInfo in XML-DSig: Purpose and Security Risks

This article provides an overview of the KeyInfo element within the XML Digital Signature (XML-DSig) specification. It explores the element’s role in conveying cryptographic key material, details the common structures used within it, and analyzes critical security considerations and vulnerabilities that developers must address when validating signatures.


What is the KeyInfo Element?

In an XML Digital Signature (XML-DSig) structure, <KeyInfo> is an optional element inside the root <Signature> element. Its primary purpose is to carry information that enables the recipient to obtain the public key or certificate necessary to validate the signature.

While <SignedInfo> contains the core cryptographic digest and signature algorithms, <KeyInfo> tells the validating party which key was used to create the signature.

Common Child Elements of KeyInfo

The XML-DSig standard defines several standard child elements that can appear within <KeyInfo>:


Security Considerations for KeyInfo

Improper handling of the KeyInfo element is one of the most common vectors for vulnerabilities in XML signature verification implementations.

1. Blindly Trusting KeyInfo Content (Untrusted Key Injection)

A critical flaw occurs when an application accepts any key present in <KeyInfo> and uses it to verify the signature without establishing trust. An attacker can modify an XML document, generate their own key pair, sign the modified content, and replace the <KeyInfo> element with their own public key or certificate.

2. Server-Side Request Forgery (SSRF) and DoS via RetrievalMethod

The <RetrievalMethod> element allows referencing key data via a URI. If the XML parser automatically resolves external URIs, attackers can supply malicious URLs pointing to internal network resources (SSRF) or large files designed to exhaust server memory and CPU (Denial of Service).

3. XML Signature Wrapping (XSW) Attacks

If <KeyInfo> is unsigned or decoupled from the payload validation logic, attackers can manipulate the XML structure to trick the signature processor into validating the signature against an attacker-controlled <KeyInfo> while the business logic consumes the malicious payload.

4. Certificate Validation Failures

When using <X509Data>, developers frequently check only that the signature matches the public key embedded in <X509Certificate>, omitting certificate validation steps.


Best Practices Summary