1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-04-13 11:50:32 +02:00

Fix: Correctly decode proxy links containing HTML entities (screenshots)

This commit is contained in:
Ralph Slooten 2023-09-06 17:28:48 +12:00
parent f4923c34ae
commit 9788a01617

View File

@ -17,6 +17,7 @@ export default {
methods: {
initScreenshot: function () {
this.loading = true
let self = this
// remove base tag, if set
let h = this.message.HTML.replace(/<base .*>/mi, '')
@ -30,9 +31,9 @@ export default {
const urlRegex = /(url\((\'|\")?(https?:\/\/[^\)\'\"]+)(\'|\")?\))/mgi;
h = h.replaceAll(urlRegex, function (match, p1, p2, p3) {
if (typeof p2 === 'string') {
return `url(${p2}proxy?url=` + encodeURIComponent(p3) + `${p2})`
return `url(${p2}proxy?url=` + encodeURIComponent(self.decodeEntities(p3)) + `${p2})`
}
return `url(proxy?url=` + encodeURIComponent(p3) + `)`
return `url(proxy?url=` + encodeURIComponent(self.decodeEntities(p3)) + `)`
})
// create temporary document to manipulate
@ -53,7 +54,7 @@ export default {
let src = i.getAttribute('href')
if (src && src.match(/^https?:\/\//i) && src.indexOf(window.location.origin + window.location.pathname) !== 0) {
i.setAttribute('href', 'proxy?url=' + encodeURIComponent(src))
i.setAttribute('href', 'proxy?url=' + encodeURIComponent(self.decodeEntities(src)))
}
}
@ -62,7 +63,7 @@ export default {
for (let i of images) {
let src = i.getAttribute('src')
if (src && src.match(/^https?:\/\//i) && src.indexOf(window.location.origin + window.location.pathname) !== 0) {
i.setAttribute('src', 'proxy?url=' + encodeURIComponent(src))
i.setAttribute('src', 'proxy?url=' + encodeURIComponent(self.decodeEntities(src)))
}
}
@ -73,7 +74,7 @@ export default {
if (src && src.match(/^https?:\/\//i) && src.indexOf(window.location.origin + window.location.pathname) !== 0) {
// replace with proxy link
i.setAttribute('background', 'proxy?url=' + encodeURIComponent(src))
i.setAttribute('background', 'proxy?url=' + encodeURIComponent(self.decodeEntities(src)))
}
}
@ -81,9 +82,17 @@ export default {
this.html = new XMLSerializer().serializeToString(doc)
},
// HTML decode function
decodeEntities: function (s) {
let e = document.createElement('div')
e.innerHTML = s
let str = e.textContent
e.textContent = ''
return str
},
doScreenshot: function () {
let self = this
let width = document.getElementById('message-view').getBoundingClientRect().width
let prev = document.getElementById('preview-html')