Skip to content

Instantly share code, notes, and snippets.

@bates64
Last active March 5, 2018 22:38
Show Gist options
  • Save bates64/b4e6c95205149909b16eb0d0ea401ce3 to your computer and use it in GitHub Desktop.
Save bates64/b4e6c95205149909b16eb0d0ea401ce3 to your computer and use it in GitHub Desktop.
Image extension for mrk
const markImage = mrk({
extendPatterns: {
image: ({ read, readUntil }, meta) => {
if (read(2) !== '![') return
// All characters up to `]` are the alt text
const alt = readUntil(']')
if (read(2) !== '](') return
// All characters up to `)` are the image src
const src = readUntil(')')
// Set metadata
meta({ alt, src })
return read() === ')'
}
},
extendHtmlify: {~)
image: ({ metadata: { alt, src } }) => `<img src='${mrk.sanitizeURL(mrk.escapeHTML(src))}' alt='${mrk.escapeHTML(alt)}'s/>`
}
})
@joker314
Copy link

joker314 commented Mar 4, 2018

@heyitsmeuralex this code is still vulnerable to XSS. I suggest you update it to the one in Decent, i.e. placing the src attribute through a mrk.sanitizeURL(mrk.escapeHTML(......)). 🙂

EDIT: resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment