mirror of
https://github.com/docusealco/docuseal.git
synced 2026-08-07 07:14:43 +00:00
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) {
|
||||
const attrs = {}
|
||||
|
||||
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 }
|
||||
|
||||
@@ -98,11 +98,29 @@ dynamic-variable {
|
||||
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) {
|
||||
const attrs = {}
|
||||
|
||||
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 }
|
||||
|
||||
@@ -646,9 +646,7 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
const container = document.createElement('div')
|
||||
|
||||
container.innerHTML = clipboardHtml
|
||||
const container = new DOMParser().parseFromString(clipboardHtml, 'text/html').body
|
||||
|
||||
const fieldNodes = [...container.querySelectorAll('dynamic-field[data-field][data-area]')]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user