Skip to content

Commit 80028fe

Browse files
Add DOMPurify for XSS protection in Markdown rendering
Includes DOMPurify library to sanitize HTML output when converting Markdown, preventing potential XSS vulnerabilities. Per this review comment: #544 (comment)
1 parent b0e905f commit 80028fe

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

site/assets/js/pages/oss-licenses.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
* Loads markdown content from the dependency report files
3131
* via Spine public repositories.
3232
*
33-
* The script requires the `https://github.com/showdownjs/showdown`
34-
* library to be loaded on the page.
33+
* The script requires both the `https://github.com/showdownjs/showdown`
34+
* Markdown converter and the `https://github.com/cure53/DOMPurify`
35+
* sanitizer to be loaded on the page before this script runs.
3536
*
3637
* See `layouts/_partials/oss-licenses/licenses.html` for usage.
3738
*/
@@ -78,8 +79,7 @@ $(
7879
clickedElement.attr(loadedAttr, 'loading');
7980
const processLoadedContent = function (data) {
8081
const html = converter.makeHtml(data);
81-
const sanitized = typeof DOMPurify !== 'undefined' ? DOMPurify.sanitize(html) : html;
82-
mdDestinationEl.html(sanitized);
82+
mdDestinationEl.html(DOMPurify.sanitize(html));
8383
clickedElement.attr(loadedAttr, 'true');
8484
makeCollapsibleTitle(mdDestinationEl, clickedElRepoName);
8585
};

site/layouts/_partials/oss-licenses/licenses.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
</div>
4747
{{ end }}
4848

49+
<!-- HTML sanitizer required by `assets/js/pages/oss-licenses.js`
50+
to prevent XSS when injecting remote Markdown as HTML. -->
51+
<script src="https://cdn.jsdelivr.net/npm/dompurify@3/dist/purify.min.js"
52+
type="text/javascript"
53+
charset="utf-8"></script>
54+
4955
<!-- The JavaScript Markdown to HTML converter.
5056
Used in the `assets/js/pages/oss-licenses.js`. -->
5157
<script src="https://cdn.rawgit.com/showdownjs/showdown/1.9.0/dist/showdown.min.js"

0 commit comments

Comments
 (0)