@xmldom/xmldom 0.8.11 → 0.8.12

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.
package/CHANGELOG.md CHANGED
@@ -4,11 +4,22 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.8.12](https://github.com/xmldom/xmldom/compare/0.8.11...0.8.12)
8
+
9
+ ### Fixed
10
+
11
+ - Security: `createCDATASection` now throws `InvalidCharacterError` when `data` contains `"]]>"`, as required by the [WHATWG DOM spec](https://dom.spec.whatwg.org/#dom-document-createcdatasection). [`GHSA-wh4c-j3r5-mjhp`](https://github.com/xmldom/xmldom/security/advisories/GHSA-wh4c-j3r5-mjhp)
12
+ - Security: `XMLSerializer` now splits CDATASection nodes whose data contains `"]]>"` into adjacent CDATA sections at serialization time, preventing XML injection via mutation methods (`appendData`, `replaceData`, `.data =`, `.textContent =`). [`GHSA-wh4c-j3r5-mjhp`](https://github.com/xmldom/xmldom/security/advisories/GHSA-wh4c-j3r5-mjhp)
13
+
14
+ Code that passes a string containing `"]]>"` to `createCDATASection` and relied on the previously unsafe behavior will now receive `InvalidCharacterError`. Use a mutation method such as `appendData` if you intentionally need `"]]>"` in a CDATASection node's data.
15
+
16
+ Thank you, [@thesmartshadow](https://github.com/thesmartshadow), for your contributions
17
+
7
18
  ## [0.8.11](https://github.com/xmldom/xmldom/compare/0.8.10...0.8.11)
8
19
 
9
20
  ### Fixed
10
21
 
11
- - update `ownerDocument` when moving nodes between documents
22
+ - update `ownerDocument` when moving nodes between documents [`#933`](https://github.com/xmldom/xmldom/pull/933) / [`#932`](https://github.com/xmldom/xmldom/issues/932)
12
23
 
13
24
  Thank you, [@shunkica](https://github.com/shunkica), for your contributions
14
25
 
package/index.d.ts CHANGED
@@ -23,6 +23,16 @@ declare module "@xmldom/xmldom" {
23
23
  }
24
24
 
25
25
  interface XMLSerializer {
26
+ /**
27
+ * Returns the result of serializing `node` to XML.
28
+ *
29
+ * __This implementation differs from the specification:__
30
+ * - CDATASection nodes whose data contains `]]>` are serialized by splitting the section
31
+ * at each `]]>` occurrence (following W3C DOM Level 3 Core `split-cdata-sections`
32
+ * default behaviour). A configurable option is not yet implemented.
33
+ *
34
+ * @see https://html.spec.whatwg.org/#dom-xmlserializer-serializetostring
35
+ */
26
36
  serializeToString(node: Node): string;
27
37
  }
28
38
 
package/lib/dom.js CHANGED
@@ -1197,7 +1197,22 @@ Document.prototype = {
1197
1197
  node.appendData(data)
1198
1198
  return node;
1199
1199
  },
1200
+ /**
1201
+ * Returns a new CDATASection node whose data is `data`.
1202
+ *
1203
+ * __This implementation differs from the specification:__
1204
+ * - calling this method on an HTML document does not throw `NotSupportedError`.
1205
+ *
1206
+ * @param {string} data
1207
+ * @returns {CDATASection}
1208
+ * @throws DOMException with code `INVALID_CHARACTER_ERR` if `data` contains `"]]>"`.
1209
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/createCDATASection
1210
+ * @see https://dom.spec.whatwg.org/#dom-document-createcdatasection
1211
+ */
1200
1212
  createCDATASection : function(data){
1213
+ if (data.indexOf(']]>') !== -1) {
1214
+ throw new DOMException(INVALID_CHARACTER_ERR, 'data contains "]]>"');
1215
+ }
1201
1216
  var node = new CDATASection();
1202
1217
  node.ownerDocument = this;
1203
1218
  node.appendData(data)
@@ -1466,6 +1481,20 @@ function ProcessingInstruction() {
1466
1481
  ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
1467
1482
  _extends(ProcessingInstruction,Node);
1468
1483
  function XMLSerializer(){}
1484
+ /**
1485
+ * Returns the result of serializing `node` to XML.
1486
+ *
1487
+ * __This implementation differs from the specification:__
1488
+ * - CDATASection nodes whose data contains `]]>` are serialized by splitting the section
1489
+ * at each `]]>` occurrence (following W3C DOM Level 3 Core `split-cdata-sections`
1490
+ * default behaviour). A configurable option is not yet implemented.
1491
+ *
1492
+ * @param {Node} node
1493
+ * @param {boolean} [isHtml]
1494
+ * @param {function} [nodeFilter]
1495
+ * @returns {string}
1496
+ * @see https://html.spec.whatwg.org/#dom-xmlserializer-serializetostring
1497
+ */
1469
1498
  XMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){
1470
1499
  return nodeSerializeToString.call(node,isHtml,nodeFilter);
1471
1500
  }
@@ -1684,7 +1713,7 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
1684
1713
  .replace(/[<&>]/g,_xmlEncoder)
1685
1714
  );
1686
1715
  case CDATA_SECTION_NODE:
1687
- return buf.push( '<![CDATA[',node.data,']]>');
1716
+ return buf.push('<![CDATA[', node.data.replace(/]]>/g, ']]]]><![CDATA[>'), ']]>');
1688
1717
  case COMMENT_NODE:
1689
1718
  return buf.push( "<!--",node.data,"-->");
1690
1719
  case DOCUMENT_TYPE_NODE:
package/lib/sax.js CHANGED
@@ -597,7 +597,7 @@ function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
597
597
  function parseInstruction(source,start,domBuilder){
598
598
  var end = source.indexOf('?>',start);
599
599
  if(end){
600
- var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
600
+ var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)$/);
601
601
  if(match){
602
602
  var len = match[0].length;
603
603
  domBuilder.processingInstruction(match[1], match[2]) ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmldom/xmldom",
3
- "version": "0.8.11",
3
+ "version": "0.8.12",
4
4
  "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
5
  "keywords": [
6
6
  "w3c",
@@ -30,6 +30,7 @@
30
30
  "scripts": {
31
31
  "lint": "eslint lib test",
32
32
  "format": "prettier --write test",
33
+ "format:check": "prettier --check test",
33
34
  "changelog": "auto-changelog --unreleased-only",
34
35
  "start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test && npm --silent run lint'",
35
36
  "stryker": "stryker run",