mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-28 19:54:43 +08:00
Protect against script injection
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
const div = document.createElement("div")
|
||||
|
||||
const tagReplacement = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"'
|
||||
}
|
||||
|
||||
function sanitizeText(value) {
|
||||
div.textContent = value
|
||||
value = div.textContent
|
||||
div.innerHTML = ""
|
||||
if (value.constructor === String) {
|
||||
return value.replace(/[&<>'"]/g, tag => tagReplacement[tag])
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user