Repository navigation
Conversation
…nicalization C14N document order compares namespace prefixes, and attribute namespace URIs then local names, by code point. nsCompare used localeCompare, so `ds` sorted before `SOAP-ENV`. attrCompare compared the joined `namespaceURI + localName` with `<`, so `urn:a`+`zb` sorted after `urn:az`+`a`, and UTF-16 code units put U+10000 before U+F900. Both canonicalizers now use a shared code point comparison. Fixes node-saml#664
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Friendly ping when you have time. Is there anything you'd like changed here? |
Fixes #664.
C14N document order (§2.2) sorts namespace nodes by prefix, and attributes by namespace URI then local name, comparing by code point. Both
C14nCanonicalizationandExclusiveCanonicalizationgot this wrong in two ways:nsCompareusedlocaleCompare, sodssorted beforeSOAP-ENV.attrComparecompared the joined stringnamespaceURI + localNamewith<. Sourn:a+zbsorted afterurn:az+a, and UTF-16 code units put U+10000 before U+F900.Both now use one
compareByCodePoint()helper inutils.ts: namespace URI first, then local name, with no-namespace attributes first (empty URI).attrCompare/nsComparekeep their signatures.Tests:
test/c14n-document-order.spec.tsruns each case through all four canonicalizers. On master 12 of them fail, for the three reasons in the issue. Two guard cases (default namespace first, no-namespace attributes first) pass before and after.npm run build && npm test && npm run lintis green (590 passing).I couldn't test non-BMP prefixes or attribute names: the pinned
@xmldom/xmldom0.8 rejects them at parse time. Non-BMP namespace URIs do parse, so the code point case is tested through those.Cross-check with libxml2: I compared the output with
xmllint --c14nandxmllint --exc-c14non 800 random documents (mixed-case prefixes,-_., digits, non-ASCII and non-BMP URIs, shuffled declarations and attributes). Master: 76 C14N and 42 exclusive mismatches. This branch: 0.Compatibility: this changes canonical bytes whenever the old order was wrong. So a signature made by an older xml-crypto over such a document will stop verifying here. The common case is inclusive C14N over a SOAP envelope that declares both
SOAP-ENVandds. Signatures from implementations that follow the spec (I checked libxml2, which xmlsec uses) over the same documents start verifying. If you'd rather ship this in 7.0 or put it behind a flag, I can change it.Summary by CodeRabbit