sanitize dynamic document attributes
This commit is contained in:
@@ -106,11 +106,29 @@ img.ProseMirror-separator {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
const DROP_ATTRS = [
|
||||||
|
'srcdoc', 'xlink:href', 'srcset', 'action', 'formaction', 'poster',
|
||||||
|
'background', 'data', 'cite', 'ping', 'longdesc', 'manifest', 'profile'
|
||||||
|
]
|
||||||
|
|
||||||
|
const SAFE_URL_REGEXP = /^(?:https?:\/\/|data:image\/|blob:|mailto:|tel:|\{)/i
|
||||||
|
|
||||||
|
function isSafeAttr (name, value) {
|
||||||
|
const lowerName = name.toLowerCase()
|
||||||
|
|
||||||
|
if (lowerName.startsWith('on') || DROP_ATTRS.includes(lowerName)) return false
|
||||||
|
if ((lowerName === 'href' || lowerName === 'src') && !SAFE_URL_REGEXP.test(value.trim())) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
function collectDomAttrs (dom) {
|
function collectDomAttrs (dom) {
|
||||||
const attrs = {}
|
const attrs = {}
|
||||||
|
|
||||||
for (let i = 0; i < dom.attributes.length; i++) {
|
for (let i = 0; i < dom.attributes.length; i++) {
|
||||||
attrs[dom.attributes[i].name] = dom.attributes[i].value
|
const { name, value } = dom.attributes[i]
|
||||||
|
|
||||||
|
if (isSafeAttr(name, value)) attrs[name] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
return { htmlAttrs: attrs }
|
return { htmlAttrs: attrs }
|
||||||
|
|||||||
@@ -98,11 +98,29 @@ dynamic-variable {
|
|||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
|
const DROP_ATTRS = [
|
||||||
|
'srcdoc', 'xlink:href', 'srcset', 'action', 'formaction', 'poster',
|
||||||
|
'background', 'data', 'cite', 'ping', 'longdesc', 'manifest', 'profile'
|
||||||
|
]
|
||||||
|
|
||||||
|
const SAFE_URL_REGEXP = /^(?:https?:\/\/|data:image\/|blob:|mailto:|tel:|\{)/i
|
||||||
|
|
||||||
|
function isSafeAttr (name, value) {
|
||||||
|
const lowerName = name.toLowerCase()
|
||||||
|
|
||||||
|
if (lowerName.startsWith('on') || DROP_ATTRS.includes(lowerName)) return false
|
||||||
|
if ((lowerName === 'href' || lowerName === 'src') && !SAFE_URL_REGEXP.test(value.trim())) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
function collectDomAttrs (dom) {
|
function collectDomAttrs (dom) {
|
||||||
const attrs = {}
|
const attrs = {}
|
||||||
|
|
||||||
for (let i = 0; i < dom.attributes.length; i++) {
|
for (let i = 0; i < dom.attributes.length; i++) {
|
||||||
attrs[dom.attributes[i].name] = dom.attributes[i].value
|
const { name, value } = dom.attributes[i]
|
||||||
|
|
||||||
|
if (isSafeAttr(name, value)) attrs[name] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
return { htmlAttrs: attrs }
|
return { htmlAttrs: attrs }
|
||||||
|
|||||||
@@ -646,9 +646,7 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const container = document.createElement('div')
|
const container = new DOMParser().parseFromString(clipboardHtml, 'text/html').body
|
||||||
|
|
||||||
container.innerHTML = clipboardHtml
|
|
||||||
|
|
||||||
const fieldNodes = [...container.querySelectorAll('dynamic-field[data-field][data-area]')]
|
const fieldNodes = [...container.querySelectorAll('dynamic-field[data-field][data-area]')]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user