Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,16 @@
var res = await fetch('views/api.html')
var html = await res.text()
var doc = new DOMParser().parseFromString(html, 'text/html')
// Sanitize parsed content before inserting: strip scripts and inline
// event handlers / javascript: URLs to avoid XSS from the fetched HTML.
doc.querySelectorAll('script').forEach(function (s) { s.remove() })
doc.querySelectorAll('*').forEach(function (el) {
Array.prototype.slice.call(el.attributes).forEach(function (attr) {
if (/^on/i.test(attr.name) || /^javascript:/i.test(attr.value)) {
el.removeAttribute(attr.name)
}
})
})
var styles = ''
doc.querySelectorAll('style').forEach(function (s) { styles += s.outerHTML })
var body = doc.body.innerHTML
Expand Down