sanitize-html 2.17.1 → 2.17.3

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.
Files changed (2) hide show
  1. package/index.js +11 -1
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -566,6 +566,15 @@ function sanitizeHtml(html, options, _recursing) {
566
566
  // your concern, don't allow them. The same is essentially true for style tags
567
567
  // which have their own collection of XSS vectors.
568
568
  result += text;
569
+ } else if ((options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && (tag === 'textarea' || tag === 'xmp')) {
570
+ // htmlparser2 treats <textarea> and <xmp> as raw text elements and
571
+ // does NOT decode entities inside them. The text is already properly
572
+ // encoded, so pass it through without additional escaping to avoid
573
+ // double-encoding. Other "nonTextTags" like <option> are not raw text
574
+ // elements in htmlparser2, so their contents are decoded and must be
575
+ // escaped below like any other text (important to prevent XSS via
576
+ // entity-encoded payloads such as <option>&lt;script&gt;...&lt;/script&gt;</option>).
577
+ result += text;
569
578
  } else if (!addedText) {
570
579
  const escaped = escapeHtml(text, false);
571
580
  if (options.textFilter) {
@@ -671,7 +680,8 @@ function sanitizeHtml(html, options, _recursing) {
671
680
 
672
681
  if (options.disallowedTagsMode === 'escape' || options.disallowedTagsMode === 'recursiveEscape') {
673
682
  const lastParsedIndex = parser.endIndex;
674
- if (lastParsedIndex != null && lastParsedIndex >= 0 && lastParsedIndex < html.length) {
683
+ if (lastParsedIndex != null && lastParsedIndex >= 0 &&
684
+ lastParsedIndex < html.length) {
675
685
  const unparsed = html.substring(lastParsedIndex);
676
686
  result += escapeHtml(unparsed);
677
687
  } else if ((lastParsedIndex == null || lastParsedIndex < 0) && html.length > 0 && result === '') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanitize-html",
3
- "version": "2.17.1",
3
+ "version": "2.17.3",
4
4
  "description": "Clean up user-submitted HTML, preserving allowlisted elements and allowlisted attributes on a per-element basis",
5
5
  "sideEffects": false,
6
6
  "main": "index.js",
@@ -24,14 +24,14 @@
24
24
  "dependencies": {
25
25
  "deepmerge": "^4.2.2",
26
26
  "escape-string-regexp": "^4.0.0",
27
- "htmlparser2": "^8.0.0",
27
+ "htmlparser2": "^10.1.0",
28
28
  "is-plain-object": "^5.0.0",
29
29
  "parse-srcset": "^1.0.2",
30
30
  "postcss": "^8.3.11"
31
31
  },
32
32
  "devDependencies": {
33
33
  "eslint": "^9.39.1",
34
- "mocha": "^10.2.0",
34
+ "mocha": "^11.7.5",
35
35
  "sinon": "^9.0.2",
36
36
  "eslint-config-apostrophe": "^6.0.2"
37
37
  },