signxml is a Python library that implements the W3C XML Signature standard (XMLDSig), used for payload security in standards like SAML 2.0, XAdES, EBICS, and WS-Security. It provides features for signing and verifying XML documents, including support for X.509 certificate chains and XAdES signatures. The library is actively maintained with regular releases, supporting modern Python versions (3.9-3.13+).
pip install signxmlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic XML signing and verification using `XMLSigner` and `XMLVerifier`. It includes placeholder instructions for generating a test certificate and key using OpenSSL. In production, always load certificates and keys securely and explicitly configure trust for verification. It also highlights the best practice of verifying the `signed_xml` attribute and asserting the signature's expected location.
Update your code to use `cryptography` types and `ca_pem_file` where applicable. Review API documentation for updated methods, especially for certificate chain validation.
Upgrade to signxml version 4.0.4 or newer immediately to mitigate these vulnerabilities.
Ensure your XML inputs do not contain DTD declarations. If you are processing external XML, sanitize or transform it to remove DTDs before passing it to signxml.
Always import `etree` from `lxml` (`from lxml import etree`) and pass `lxml.etree` objects or raw XML strings directly to signxml. Avoid converting to/from `xml.etree.ElementTree` objects.
When verifying, access `result.signed_xml` and incorporate `expect_config=SignatureConfiguration(location='./')` in your `verify()` calls where appropriate.
Always specify trust anchors during verification (e.g., `verifier.verify(..., x509_cert=my_trusted_cert)` or `ca_pem_file="/path/to/my_ca.pem")`).
Do not pretty-print or reformat signed XML documents if their signatures are to remain valid.
pip install signxml
Ensure the XML document actually contains a `<ds:Signature>` element and, if necessary, provide the correct `signature_xpath` argument to `XMLVerifier.verify()`.
Verify that the correct public key or certificate is being used, ensure the signed document has not been altered, and confirm that the canonicalization and digest methods match those used during signing.
Add a namespace declaration to the root element of your XML document, such as `<root xmlns="http://example.com/ns">`.