samlesa 4.7.4 → 4.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,64 @@ function toNodeArray(result) {
15
15
  }
16
16
  return [];
17
17
  }
18
+ function isElementNode(node) {
19
+ return !!node && node.nodeType === 1;
20
+ }
21
+ function isNamespaceDeclaration(attributeName) {
22
+ return attributeName === 'xmlns' || attributeName.startsWith('xmlns:');
23
+ }
24
+ function getNamespaceDeclarationMap(node) {
25
+ const declarations = new Map();
26
+ const attributes = node.attributes;
27
+ for (let index = 0; index < attributes.length; index += 1) {
28
+ const attribute = attributes.item(index);
29
+ if (attribute && isNamespaceDeclaration(attribute.name)) {
30
+ declarations.set(attribute.name, attribute.value);
31
+ }
32
+ }
33
+ return declarations;
34
+ }
35
+ function collectInheritedNamespaceDeclarations(node) {
36
+ const inheritedDeclarations = new Map();
37
+ let current = node.parentNode;
38
+ while (isElementNode(current)) {
39
+ for (const [name, value] of getNamespaceDeclarationMap(current)) {
40
+ if (!inheritedDeclarations.has(name)) {
41
+ inheritedDeclarations.set(name, value);
42
+ }
43
+ }
44
+ current = current.parentNode;
45
+ }
46
+ return inheritedDeclarations;
47
+ }
48
+ function escapeAttributeValue(value) {
49
+ return value
50
+ .replace(/&/g, '&amp;')
51
+ .replace(/"/g, '&quot;')
52
+ .replace(/</g, '&lt;')
53
+ .replace(/>/g, '&gt;');
54
+ }
55
+ function rootHasNamespaceDeclaration(serializedXml, name) {
56
+ const rootStartTag = serializedXml.match(/^<[^>]+>/)?.[0] || '';
57
+ return new RegExp(`(?:^|\\s)${name.replace(':', '\\:')}\\s*=`).test(rootStartTag);
58
+ }
59
+ function serializeWithInheritedNamespaces(node) {
60
+ if (!isElementNode(node)) {
61
+ return node.toString();
62
+ }
63
+ let serializedXml = node.toString();
64
+ const declarationsToAdd = [];
65
+ for (const [name, value] of collectInheritedNamespaceDeclarations(node)) {
66
+ if (!rootHasNamespaceDeclaration(serializedXml, name)) {
67
+ declarationsToAdd.push(`${name}="${escapeAttributeValue(value)}"`);
68
+ }
69
+ }
70
+ if (declarationsToAdd.length === 0) {
71
+ return serializedXml;
72
+ }
73
+ serializedXml = serializedXml.replace(/^<([^\s/>]+)([^>]*)>/, (_match, tagName, attributes) => `<${tagName} ${declarationsToAdd.join(' ')}${attributes}>`);
74
+ return serializedXml;
75
+ }
18
76
  const certUse = wording.certUse;
19
77
  const docParser = new DOMParser();
20
78
  function resolvePublicCertificates(signatureNode, opts) {
@@ -44,7 +102,7 @@ function extractResolvedMessage(rootNode) {
44
102
  if (resolvedNodes.length === 0) {
45
103
  return null;
46
104
  }
47
- return resolvedNodes[0].toString();
105
+ return serializeWithInheritedNamespaces(resolvedNodes[0]);
48
106
  }
49
107
  function verifySignature(xml, signatureNodes, opts) {
50
108
  for (const signatureNode of signatureNodes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samlesa",
3
- "version": "4.7.4",
3
+ "version": "4.7.5",
4
4
  "description": "High-level API for Single Sign On (SAML 2.0) baseed on samlify ",
5
5
  "main": "build/index.js",
6
6
  "keywords": [
@@ -1 +1 @@
1
- {"version":3,"file":"libsamlSoap.d.ts","sourceRoot":"","sources":["../../src/libsamlSoap.ts"],"names":[],"mappings":"AAKA,OAAgB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAiBjE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,iBAAiB,GAAG,kBAAkB,CAAC;IAC7C,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AA4HD,iBAAe,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAoCpH;;;;AAED,wBAEE"}
1
+ {"version":3,"file":"libsamlSoap.d.ts","sourceRoot":"","sources":["../../src/libsamlSoap.ts"],"names":[],"mappings":"AAKA,OAAgB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AA2FjE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,iBAAiB,GAAG,kBAAkB,CAAC;IAC7C,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AA4HD,iBAAe,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAoCpH;;;;AAED,wBAEE"}