sanitize-html 2.17.4 → 2.17.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.
Files changed (3) hide show
  1. package/README.md +8 -1
  2. package/index.js +12 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -182,7 +182,14 @@ selfClosing: [ 'img', 'br', 'hr', 'area', 'base', 'basefont', 'input', 'link', '
182
182
  // URL schemes we permit
183
183
  allowedSchemes: [ 'http', 'https', 'ftp', 'mailto', 'tel' ],
184
184
  allowedSchemesByTag: {},
185
- allowedSchemesAppliedToAttributes: [ 'href', 'src', 'cite' ],
185
+ allowedSchemesAppliedToAttributes: [
186
+ 'href', 'src', 'cite',
187
+ 'action', 'formaction', 'data', 'xlink:href',
188
+ 'poster', 'background', 'ping',
189
+ 'longdesc', 'usemap', 'codebase', 'classid', 'archive',
190
+ 'profile', 'manifest', 'itemid',
191
+ 'dynsrc', 'lowsrc'
192
+ ],
186
193
  allowProtocolRelative: true,
187
194
  enforceHtmlBoundary: false,
188
195
  parseStyleAttributes: true
package/index.js CHANGED
@@ -440,11 +440,11 @@ function sanitizeHtml(html, options, _recursing) {
440
440
  return;
441
441
  }
442
442
  }
443
- if (a === 'srcset') {
443
+ if (a === 'srcset' || a === 'imagesrcset') {
444
444
  try {
445
445
  let parsed = parseSrcset(value);
446
446
  parsed.forEach(function(value) {
447
- if (naughtyHref('srcset', value.url)) {
447
+ if (naughtyHref(a, value.url)) {
448
448
  value.evil = true;
449
449
  }
450
450
  });
@@ -566,13 +566,13 @@ function sanitizeHtml(html, options, _recursing) {
566
566
 
567
567
  if (options.disallowedTagsMode === 'completelyDiscard' && !tagAllowed(tag)) {
568
568
  text = '';
569
- } else if ((options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && ((tag === 'script') || (tag === 'style'))) {
569
+ } else if (tag && tagAllowed(tag) && (options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && ((tag === 'script') || (tag === 'style'))) {
570
570
  // htmlparser2 gives us these as-is. Escaping them ruins the content. Allowing
571
571
  // script tags is, by definition, game over for XSS protection, so if that's
572
572
  // your concern, don't allow them. The same is essentially true for style tags
573
573
  // which have their own collection of XSS vectors.
574
574
  result += text;
575
- } else if ((options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && (tag === 'textarea' || tag === 'xmp')) {
575
+ } else if (tag && tagAllowed(tag) && (options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && (tag === 'textarea' || tag === 'xmp')) {
576
576
  // htmlparser2 treats <textarea> and <xmp> as raw text elements and
577
577
  // does NOT decode entities inside them. The text is already properly
578
578
  // encoded, so pass it through without additional escaping to avoid
@@ -957,7 +957,14 @@ sanitizeHtml.defaults = {
957
957
  // URL schemes we permit
958
958
  allowedSchemes: [ 'http', 'https', 'ftp', 'mailto', 'tel' ],
959
959
  allowedSchemesByTag: {},
960
- allowedSchemesAppliedToAttributes: [ 'href', 'src', 'cite' ],
960
+ allowedSchemesAppliedToAttributes: [
961
+ 'href', 'src', 'cite',
962
+ 'action', 'formaction', 'data', 'xlink:href',
963
+ 'poster', 'background', 'ping',
964
+ 'longdesc', 'usemap', 'codebase', 'classid', 'archive',
965
+ 'profile', 'manifest', 'itemid',
966
+ 'dynsrc', 'lowsrc'
967
+ ],
961
968
  allowProtocolRelative: true,
962
969
  enforceHtmlBoundary: false,
963
970
  parseStyleAttributes: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanitize-html",
3
- "version": "2.17.4",
3
+ "version": "2.17.5",
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",