Concept Flow - Why security matters in Vue
User Input
Vue Template
Rendering
Potential Security Risk
Safe Handling
Secure App
This flow shows how user input goes through Vue templates to rendering, where safe or unsafe handling affects app security.
<template>
<div>{{ userInput }}</div>
</template>
<script setup>
const userInput = '<img src=x onerror=alert(1)>'
</script>| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Vue reads userInput | '<img src=x onerror=alert(1)>' | Stores as string |
| 2 | Vue renders {{ userInput }} | Escapes HTML tags | Displays literal text '<img src=x onerror=alert(1)>' |
| 3 | User sees output | No script runs | Safe display |
| 4 | If v-html used instead | Injects raw HTML | Script runs, alert pops |
| 5 | App vulnerable to XSS | Security risk | Bad outcome |
| Variable | Start | After Render | Final |
|---|---|---|---|
| userInput | '' | '<img src=x onerror=alert(1)>' | '<img src=x onerror=alert(1)>' |
Vue escapes HTML in {{ }} to prevent scripts running.
Unsafe use of v-html can inject scripts.
Always sanitize or avoid raw HTML injection.
Security protects users from attacks like XSS.
Check user input carefully before rendering.