Skip to content

Instantly share code, notes, and snippets.

@bharathvaj-ganesan
Created February 8, 2018 08:38
Show Gist options
  • Select an option

  • Save bharathvaj-ganesan/f7e945ae953b1b5c01e6f702d511a854 to your computer and use it in GitHub Desktop.

Select an option

Save bharathvaj-ganesan/f7e945ae953b1b5c01e6f702d511a854 to your computer and use it in GitHub Desktop.
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/0.8.2/purify.min.js"></script>
<script>
function sanitize(strings, ...values) {
const dirty = strings.reduce((prev, next, i) => `${prev}${next}${values[i] || ''}`, '');
console.log(dirty);
console.log(aboutMe);
return DOMPurify.sanitize(aboutMe);
}
const name = 'petyr baelish';
const aboutMe = `I love to do evil <img src="http://unsplash.it/100/100?random" onload="alert('I hacked you. Haha');" />`;
const html = sanitize`
<h3>${name}</h3>
<p>${aboutMe}</p>
`;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment