Performance: XSS prevention in templates
HIGH IMPACT
This affects page security and rendering speed by controlling how user input is handled and displayed in templates.
<template>
<div>{{ userInput }}</div>
</template>
<script setup>
const userInput = '<img src=x onerror=alert(1)>'
</script><template> <div v-html="userInput"></div> </template> <script setup> const userInput = '<img src=x onerror=alert(1)>' </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using v-html with untrusted input | Adds nodes dynamically | Triggers multiple reflows if scripts modify layout | High due to repaints and possible script execution | [X] Bad |
| Using {{ }} interpolation for user input | No extra nodes, text only | No reflows caused by script injection | Low paint cost, stable layout | [OK] Good |