diff --git a/CHANGELOG.md b/CHANGELOG.md index c822d9b..dc84443 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog -- Protocol-relative URLs are properly supported for script tags +## 2.7.1 (2022-07-20) + +- Protocol-relative URLs are properly supported for script tags. Thanks to [paweljq](https://github.com/paweljq). +- A denial-of-service vulnerability has been fixed by replacing global regular expression replacement logic for comment removal with a new implementation. Thanks to Nariyoshi Chida of NTT Security Japan for pointing out the issue. ## 2.7.0 (2022-02-04) diff --git a/index.js b/index.js index 754bf10..4a4c2d1 100644 --- a/index.js +++ b/index.js @@ -612,7 +612,17 @@ function sanitizeHtml(html, options, _recursing) { // Clobber any comments in URLs, which the browser might // interpret inside an XML data island, allowing // a javascript: URL to be snuck through - href = href.replace(//g, ''); + while (true) { + const firstIndex = href.indexOf('', firstIndex + 4); + if (lastIndex === -1) { + break; + } + href = href.substring(0, firstIndex) + href.substring(lastIndex + 3); + } // Case insensitive so we don't get faked out by JAVASCRIPT #1 // Allow more characters after the first so we don't get faked // out by certain schemes browsers accept diff --git a/package.json b/package.json index ab4981c..6054aff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sanitize-html", - "version": "2.7.0", + "version": "2.7.1", "description": "Clean up user-submitted HTML, preserving allowlisted elements and allowlisted attributes on a per-element basis", "sideEffects": false, "main": "index.js",