Skip to content

Regression: cleanup_namespaces removes also xs + xsi prefixes #333

Description

The cleanup_namespaces call added in #325 considers only namespaces used in XML Element and Attribute names, but not in attribute values.

The xs namespaces is used only in values of of xsi:type attributes, such as in:

        <saml:Attribute Name="http://macedir.org/entity-category" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
          <saml:AttributeValue xsi:type="xs:string">https://refeds.org/category/code-of-conduct/v2</saml:AttributeValue>
        </saml:Attribute>

The LXML cleanup_namespaces considers it unused and removes, resulting into metadata that fails schema validation:

xmllint --noout --schema /opt/mdtool/app/web/schemas/schema.xsd /var/www/html/metadata/tuakiri-dev-metadata-signed.xml
/var/www/html/metadata/tuakiri-dev-metadata-signed.xml:1095: element AttributeValue: Schemas validity error : Element '{urn:oasis:names:tc:SAML:2.0:assertion}AttributeValue', attribute '{http://www.w3.org/2001/XMLSchema-instance}type': The QName value 'xs:string' has no corresponding namespace declaration in scope.
/var/www/html/metadata/tuakiri-dev-metadata-signed.xml:1096: element AttributeValue: Schemas validity error : Element '{urn:oasis:names:tc:SAML:2.0:assertion}AttributeValue', attribute '{http://www.w3.org/2001/XMLSchema-instance}type': The QName value 'xs:string' has no corresponding namespace declaration in scope.
/var/www/html/metadata/tuakiri-dev-metadata-signed.xml:1099: element AttributeValue: Schemas validity error : Element '{urn:oasis:names:tc:SAML:2.0:assertion}AttributeValue', attribute '{http://www.w3.org/2001/XMLSchema-instance}type': The QName value 'xs:string' has no corresponding namespace declaration in scope.
/var/www/html/metadata/tuakiri-dev-metadata-signed.xml:1100: element AttributeValue: Schemas validity error : Element '{urn:oasis:names:tc:SAML:2.0:assertion}AttributeValue', attribute '{http://www.w3.org/2001/XMLSchema-instance}type': The QName value 'xs:string' has no corresponding namespace declaration in scope.
/var/www/html/metadata/tuakiri-dev-metadata-signed.xml fails to validate

And also fails with Shibboleth SP using MetadataProvider with validate="true":

2026-09-03 11:06:07 ERROR XMLTooling.ParserPool : fatal error on line 6018, column 53, message: prefix 'xs' can not be r
esolved to namespace URI
2026-09-03 11:06:07 ERROR OpenSAML.MetadataProvider.XML : error while loading resource (/var/cache/shibboleth/metadata.t
uakiri-test.xml): XML error(s) during parsing, check log for specifics
2026-09-03 11:06:07 CRIT OpenSAML.MetadataProvider.Chaining : failure initializing MetadataProvider: XML error(s) during
 parsing, check log for specifics

This can be solved with lxml.etree.cleanup_namespaces keep_ns_prefixes parameter.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions