Skip to content

Commit 82b7800

Browse files
authored
Merge pull request #1691 from hackmdio/bugfix/fix-gist-id-stored-XSS
Strip HTML tags for gist id to avoid stored XSS on showing error [Security Issue]
2 parents 282fcab + 2eefe77 commit 82b7800

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

public/js/extra.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,20 @@ export function finishView (view) {
330330
})
331331
// gist
332332
view.find('code[data-gist-id]').each((key, value) => {
333-
if ($(value).children().length === 0) { $(value).gist(window.viewAjaxCallback) }
333+
if ($(value).children().length === 0) {
334+
// strip HTML tags to avoid stored XSS
335+
const gistid = value.getAttribute('data-gist-id')
336+
value.setAttribute('data-gist-id', stripTags(gistid))
337+
const gistfile = value.getAttribute('data-gist-file')
338+
if (gistfile) value.setAttribute('data-gist-file', stripTags(gistfile))
339+
const gistline = value.getAttribute('data-gist-line')
340+
if (gistline) value.setAttribute('data-gist-line', stripTags(gistline))
341+
const gisthighlightline = value.getAttribute('data-gist-highlight-line')
342+
if (gisthighlightline) value.setAttribute('data-gist-highlight-line', stripTags(gisthighlightline))
343+
const gistshowloading = value.getAttribute('data-gist-show-loading')
344+
if (gistshowloading) value.setAttribute('data-gist-show-loading', stripTags(gistshowloading))
345+
$(value).gist(window.viewAjaxCallback)
346+
}
334347
})
335348
// sequence diagram
336349
const sequences = view.find('div.sequence-diagram.raw').removeClass('raw')

0 commit comments

Comments
 (0)