Skip to content

Commit

Permalink
Merge pull request #1691 from hackmdio/bugfix/fix-gist-id-stored-XSS
Browse files Browse the repository at this point in the history
Strip HTML tags for gist id to avoid stored XSS on showing error [Security Issue]
  • Loading branch information
a60814billy authored Jun 16, 2021
2 parents 282fcab + 2eefe77 commit 82b7800
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion public/js/extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,20 @@ export function finishView (view) {
})
// gist
view.find('code[data-gist-id]').each((key, value) => {
if ($(value).children().length === 0) { $(value).gist(window.viewAjaxCallback) }
if ($(value).children().length === 0) {
// strip HTML tags to avoid stored XSS
const gistid = value.getAttribute('data-gist-id')
value.setAttribute('data-gist-id', stripTags(gistid))
const gistfile = value.getAttribute('data-gist-file')
if (gistfile) value.setAttribute('data-gist-file', stripTags(gistfile))
const gistline = value.getAttribute('data-gist-line')
if (gistline) value.setAttribute('data-gist-line', stripTags(gistline))
const gisthighlightline = value.getAttribute('data-gist-highlight-line')
if (gisthighlightline) value.setAttribute('data-gist-highlight-line', stripTags(gisthighlightline))
const gistshowloading = value.getAttribute('data-gist-show-loading')
if (gistshowloading) value.setAttribute('data-gist-show-loading', stripTags(gistshowloading))
$(value).gist(window.viewAjaxCallback)
}
})
// sequence diagram
const sequences = view.find('div.sequence-diagram.raw').removeClass('raw')
Expand Down

0 comments on commit 82b7800

Please sign in to comment.