Skip to content

URGENT -- fix: Add lxml 6.x compatibility for XML signature namespace handling#444

Merged
felps-dev merged 2 commits intoTadaSoftware:mainfrom
nuvelbr:master
Feb 5, 2026
Merged

URGENT -- fix: Add lxml 6.x compatibility for XML signature namespace handling#444
felps-dev merged 2 commits intoTadaSoftware:mainfrom
nuvelbr:master

Conversation

@felps-dev
Copy link
Collaborator

Summary

This PR adds compatibility with lxml 6.x which introduced a breaking change in how default namespaces are handled internally.

The Problem

When signxml creates signature elements using a default namespace (nsmap={None: "http://www.w3.org/2000/09/xmldsig#"}), lxml 6.x no longer associates the namespace with the element's internal tag property. This causes XPath queries with namespace prefixes to fail, even though the serialized XML contains the correct xmlns= declaration.

lxml Version Element tag property XPath with namespace
5.x {http://...}Signature Works
6.x Signature Fails

The Fix

  1. Reparse XML after signing - Serialize and reparse the signed XML so lxml correctly associates namespaces from the xmlns= declarations
  2. Update dependency constraints - Allow lxml >=5.4.0 and signxml >=4.1.0 (removes upper bounds)
  3. Fix certificate test - Use tempfile.gettempdir() instead of hardcoded /tmp/ for cross-platform compatibility (macOS uses /var/folders/...)

Changes

  • pynfe/processamento/assinatura.py - Add reparse step after signing
  • pyproject.toml - Update lxml and signxml version constraints
  • requirements.txt - Pin minimum versions for all dependencies
  • tests/test_certificadoA1.py - Use platform-independent temp directory

Testing

All 134 tests pass with:

  • lxml 6.0.2
  • signxml 4.2.2
  • cryptography 46.0.4

References

- Reparse XML after signing to ensure namespaces are correctly associated
  with elements (required for lxml 6.x when using default namespace)
- Update dependency constraints to allow lxml >=5.4.0 and signxml >=4.1.0
- Fix certificate test to use platform-independent temp directory

lxml 6.0 changed how elements with default namespaces (xmlns without prefix)
are handled internally. Elements created with nsmap={None: "..."} no longer
have the namespace in their tag property, causing XPath queries with
namespace prefixes to fail.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@felps-dev felps-dev changed the title fix: Add lxml 6.x compatibility for XML signature namespace handling URGENT -- fix: Add lxml 6.x compatibility for XML signature namespace handling Feb 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds compatibility with lxml 6.x, which introduced a breaking change in how default namespaces are handled internally. When signxml creates signature elements with a default namespace, lxml 6.x no longer associates the namespace with the element's internal tag property, causing XPath queries to fail despite correct xmlns declarations in the serialized XML.

Changes:

  • Added a reparse step after XML signing to ensure namespaces are correctly associated with elements for lxml 6.x compatibility
  • Updated dependency constraints to allow lxml >=5.4.0 and signxml >=4.1.0 (removing upper bounds)
  • Fixed certificate test to use cross-platform temp directory instead of hardcoded /tmp/

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
pynfe/processamento/assinatura.py Added serialize-reparse workaround after signing to fix lxml 6.x namespace handling; reuses serialized string efficiently
pyproject.toml Updated lxml and signxml to use minimum version constraints without upper bounds
requirements.txt Added minimum version constraints for all dependencies (requests, lxml, signxml, cryptography)
tests/test_certificadoA1.py Fixed test to use platform-independent tempfile.gettempdir() instead of hardcoded /tmp/

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

juniortada
juniortada previously approved these changes Feb 4, 2026
leogregianin
leogregianin previously approved these changes Feb 4, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@felps-dev felps-dev merged commit 5c65c24 into TadaSoftware:main Feb 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants