Challenge - 5 Problems
XSS Prevention Mastery in Vue
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will this Vue template render?
Consider this Vue 3 template snippet:
If
<template>
<div>{{ userInput }}</div>
</template>If
userInput contains the string <script>alert('XSS')</script>, what will the browser display?Vue
<template>
<div>{{ userInput }}</div>
</template>
<script setup>
import { ref } from 'vue'
const userInput = ref("<script>alert('XSS')</script>")
</script>Attempts:
2 left
💡 Hint
Think about how Vue handles interpolation with double curly braces.
✗ Incorrect
Vue escapes HTML special characters inside {{ }} interpolation by default, so the script tag is shown as text, not executed.
📝 Syntax
intermediate2:00remaining
Which Vue directive safely renders raw HTML?
You want to render some HTML content stored in a variable
htmlContent inside your Vue template. Which directive correctly renders the HTML without escaping it?Attempts:
2 left
💡 Hint
One directive tells Vue to insert raw HTML inside an element.
✗ Incorrect
The v-html directive inserts raw HTML inside the element. The others either escape HTML or set text content.
🔧 Debug
advanced2:00remaining
Why does this Vue component cause an XSS vulnerability?
This Vue component uses
What is the main security risk here?
v-html to render user input:<template> <div v-html="userInput"></div> </template>
What is the main security risk here?
Vue
<template> <div v-html="userInput"></div> </template> <script setup> import { ref } from 'vue' const userInput = ref('<img src=x onerror=alert(1)>') </script>
Attempts:
2 left
💡 Hint
Think about what happens when you insert raw HTML from untrusted sources.
✗ Incorrect
v-html inserts raw HTML without escaping, so if userInput contains malicious code, it runs in the browser causing XSS.
🧠 Conceptual
advanced2:00remaining
How does Vue's template interpolation prevent XSS?
Which mechanism does Vue use to prevent XSS attacks when rendering variables inside double curly braces {{ }}?
Attempts:
2 left
💡 Hint
Think about how browsers treat escaped characters.
✗ Incorrect
Vue escapes special HTML characters so the browser treats them as text, not code, preventing script execution.
❓ state_output
expert2:00remaining
What is the output after updating user input with v-html?
Given this Vue 3 component:
What happens when the user clicks the Update button?
<template>
<div v-html="content"></div>
<button @click="updateContent">Update</button>
</template>
<script setup>
import { ref } from 'vue'
const content = ref('<p>Hello</p>')
function updateContent() {
content.value = '<img src=x onerror=alert(42)>'
}
</script>What happens when the user clicks the Update button?
Vue
<template> <div v-html="content"></div> <button @click="updateContent">Update</button> </template> <script setup> import { ref } from 'vue' const content = ref('<p>Hello</p>') function updateContent() { content.value = '<img src=x onerror=alert(42)>' } </script>
Attempts:
2 left
💡 Hint
Remember what v-html does when its bound value changes.
✗ Incorrect
v-html inserts raw HTML and updates dynamically, so the image with onerror runs the alert when loaded.