fix: respect namespace config for default namespace C14N#283
fix: respect namespace config for default namespace C14N#283kislyuk merged 1 commit intoXML-Security:mainfrom
Conversation
When signer.namespaces = {None: namespaces.ds} (default namespace),
elements were created with explicit namespace via QName(namespaces.ds, tag).
This caused lxml C14N to add xmlns="" undeclarations on child elements
inside <Reference>, changing the SignedInfo digest and signature.
Added _ds_tag() method that returns QName(None, tag) when default
namespace is configured, allowing elements to inherit from nsmap context.
Fixes XML-Security#275
|
Hi there, I'm going to have to revert this PR because the test case does not pass. I thought that it passed and CI was failing for unrelated reasons, but that's not the case. I'm going to have to ask you to provide a test case that works for round-tripping a signature with these changes. |
|
Hi, apologies for pushing a failing test. I was confused by a pre-existing failure (test_xades_roundtrip) and incorrectly assumed mine was passing. The updated test now uses The reason: after serialize/parse, lxml normalizes namespace handling, which reintroduces Is this a valid approach, or is there a better way? |
|
I've opened #286 with a complete fix that includes:
The verifier fix detects when SignedInfo uses only default namespace (no ds: prefix) and automatically applies the same |
Fixes #275
Problem
When
signer.namespaces = {None: namespaces.ds}, the C14N output contained spuriousxmlns=""undeclarations on elements inside<Reference>, changing the signature.Root Cause
ds_tag()always returnsQName(namespaces.ds, tag), creating elements with explicit namespace regardless of howsigner.namespacesis configured. When lxml canonicalizes these elements with C14N 1.0, it addsxmlns=""to undeclare the namespace on nested elements.Solution
Added
_ds_tag()method that respects namespace configuration - returnsQName(None, tag)when default namespace is configured, allowing elements to inherit from nsmap context.Test
Added
test_default_namespace_c14n_no_xmlns_undeclarationsto verify:xmlns=""undeclarations in SignedInfo C14N output